Timer managers
The timer manager combines the functions of the asynchronous beans alarm manager and asynchronous scope. So, when a timer manager is created, it internally uses an asynchronous scope to provide the timer manager life cycle functions.
Deprecated feature: Asynchronous beans and CommonJ Timer and WorkManager are deprecated asynchronous scheduling facilities. Concurrency Utilities for Java EE replaces these deprecated scheduling facilities. v9 still supports asynchronous beans and CommonJ Timer and WorkManager. However, the v9 documentation focuses on Concurrency Utilities for Java EE. If we do not find the information about timer managers that you seek in the v9 documentation, see the v8.5.5 documentation.depfeat
We can look up the timer manager in the JNDI name space. This capability is different from the alarm manager that is retrieved through the asynchronous beans scope. Each lookup of the timer manager returns a new logical timer manager that can be destroyed independently of all other timer managers.
A timer manager can be configured with a number of thread pools through the administrative console. For deployment we can bind this timer manager to a resource reference at assembly time, so the resource reference can be used by the application to look up the timer manager.
The Java code to look up the timer manager is:
InitialContext ic = new InitialContext(); TimerManager tm = (TimerManager)ic.lookup("java:comp/env/tm/TimerManager");The programming model for setting up the alarm listener and the timer listener is different. The following code example shows that difference.
Set up the timer listener
Asynchronous beans CommonJ public class ABAlarmListener implements AlarmListener { public void fired(Alarm alarm) { System.out.println("Alarm fired. Context =" + alarm.getContext()); } public class StockQuoteTimerListener implements TimerListener { String context; String url; public StockQuoteTimerListener(String context, String url){ this.context = context; This.url = url; } public void timerExpired(Timer timer) { System.out.println("Timer fired. Context ="+ ((StockQuoteTimerListener)timer.getTimerListener()) .getContext()); } public String getContext() { return context; } }When using the CommonJ timer manager remember to configure resource references in the application.xml within the java:app or java:global contexts. For example, the application.xml file should look similar to the following:
<res-ref-name>java:app/env/timerManger</res-ref-name>and the ibm-application-bnd.xml file should contain something similar to the following:<resource-ref-name="java:app/env/timerManager" binding-name="tm/default"/>Ensure that your Spring configuration file contains a similar value:value="java:app/env/timerManager"
Configure timer managers