4 Replies Latest reply on Nov 15, 2002 7:48 PM by jdeng

    Working with Timer service


      Hello, folks. How can I use the Timer service in JBoss?

      I've read some docs about javax.management.timer.Timer class, and understood that I need to write a class that implements NotificationListener. Ok, this is done. Now, how can I register my class with the timer service?

      Just to paint the picture a little more prettier: I need to run a task at fixed intervals. This task will call some methods on my application's EJB's. I've coded the task, now I need to know how to make JBoss call my task at regular intervals.

        • 1. Re: Working with Timer service

          You might want to look at scheduler-service.xml,
          it is more user friendly than the plain jmx timer.

          You don't need to worry about creating/starting
          the timer or registering the notification listener.

          You can also add so the scheduled task
          won't start until the ejb(s) are deployed.


          • 2. Re: Working with Timer service


            I understand what you are saying. But I have similar problem because I am trying the build an application that will run across most application servers (JBoss being one of them). Even though J2EE does not specify what timer service to use. But the most prevelent one seems to be the javax.management.timer.Timer, which works for other application server such as WebLogic. But it seems to have problem inside jboss receiving timer notification (hanndleNotification not called). I am registering with the Timer using following code snippet:
            timer = new Timer();
            if (!timer.isActive()) {
            timer.addNotificationListener(this, this, null);

            My question to you is what is the limitation of using Timer inside jboss?


            • 3. Re: Working with Timer service

              You have to register the timer in the MBeanServer.

              You have to get add a notifiction id
              where you configure the repeats, start time, etc.

              The jmx timer is pretty simple and requires a lot
              of booking keeping. If it fits your purpose there
              are no limitations.


              • 4. Re: Working with Timer service

                Thanks Adrian. Your suggestion is on the point. Besides what you suggested I also have to create a little wrapper on top of timer MBean. You can not direcly use javax.management.timer.Timer directly. But the wrapping is really simple. This way you can basically write a universal scheduler that works across all application server.