이 콘텐츠는 선택한 언어로 제공되지 않습니다.

30.5. EJB Timer Configuration


The J2EE timer service allows for any EJB object to register for a timer callback either at a designated time in the future. Timer events can be used for auditing, reporting or other cleanup tasks that need to need to happen at some given time in the future. Timer events are intended to be persistent and should be executed even in the event of a server failure. Coding to EJB timers is a standard part of the J2EE specification, so we will not explore the programming model. We will, instead, look at the configuration of the timer service in JBoss so that you can understand how to make timers work best in your environment
The EJB timer service is configure by several related MBeans in the ejb-deployer.xml file. The primary MBean is the EJBTimerService MBean.
<mbean code="org.jboss.ejb.txtimer.EJBTimerServiceImpl" name="jboss.ejb:service=EJBTimerService">
    <attribute name="RetryPolicy">jboss.ejb:service=EJBTimerService,retryPolicy=fixedDelay</attribute>
    <attribute name="PersistencePolicy">jboss.ejb:service=EJBTimerService,persistencePolicy=database</attribute>
    <attribute name="TimerIdGeneratorClassName">org.jboss.ejb.txtimer.BigIntegerTimerIdGenerator</attribute>
    <attribute name="TimedObjectInvokerClassName">org.jboss.ejb.txtimer.TimedObjectInvokerImpl</attribute>
</mbean>
Copy to Clipboard Toggle word wrap
The EJBTimerService has the following configurable attributes:
  • RetryPolicy: This is name of the MBean that implements the retry policy. The MBean must support the org.jboss.ejb.txtimer.RetryPolicy interface. JBoss provides one implementation, FixedDelayRetryPolicy, which will be described later.
  • PersistencePolicy: This is the name of the MBean that implements the persistence strategy for saving timer events. The MBean must support the org.jboss.ejb.txtimer.PersistencePolicy interface. JBoss provides two implementations, NoopPersistencePolicy and DatabasePersistencePolicy, which will be described later.
  • TimerIdGeneratorClassName: This is the name of a class that provides the timer ID generator strategy. This class must implement the org.jboss.ejb.txtimer.TimerIdGenerator interface. JBoss provides the org.jboss.ejb.txtimer.BigIntegerTimerIdGenerator implementation.
  • TimedObjectInvokerClassname: This is the name of a class that provides the timer method invocation strategy. This class must implement the org.jboss.ejb.txtimer.TimedObjectInvoker interface. JBoss provides the org.jboss.ejb.txtimer.TimedObjectInvokerImpl implementation.
The retry policy MBean definition used is shown here:
<mbean code="org.jboss.ejb.txtimer.FixedDelayRetryPolicy"
       name="jboss.ejb:service=EJBTimerService,retryPolicy=fixedDelay">
    <attribute name="Delay">100</attribute>
</mbean>
Copy to Clipboard Toggle word wrap
The retry policy takes one configuration value:
  • Delay: This is the delay (ms) before retrying a failed timer execution. The default delay is 100ms.
If EJB timers do not need to be persisted, the NoopPersistence policy can be used. This MBean is commented out by default, but when enabled will look like this:
<mbean code="org.jboss.ejb.txtimer.NoopPersistencePolicy" 
       name="jboss.ejb:service=EJBTimerService,persistencePolicy=noop"/>
Copy to Clipboard Toggle word wrap
Most applications that use timers will want timers to be persisted. For that the DatabasePersitencePolicy MBean should be used.
<mbean code="org.jboss.ejb.txtimer.DatabasePersistencePolicy" 
       name="jboss.ejb:service=EJBTimerService,persistencePolicy=database">
    <!-- DataSource JNDI name -->
    <depends optional-attribute-name="DataSource">jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>
    <!-- The plugin that handles database persistence -->
    <attribute name="DatabasePersistencePlugin">org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin</attribute>
</mbean>
Copy to Clipboard Toggle word wrap
  • DataSource: This is the MBean for the DataSource that timer data will be written to.
  • DatabasePersistencePlugin: This is the name of the class the implements the persistence strategy. This should be org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat