+

Search Tips   |   Advanced Search

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.

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.

model for setting 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;
    }
 }


Related tasks

  • Configure timer managers Concept topic