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.
You can look up the timer manager in the Java™ Naming and Directory Interface (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 you 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.
InitialContext ic = new InitialContext(); TimerManager tm = (TimerManager)ic.lookup(“java:comp/env/tm/TimerManager”);
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; } } |