Version 5

    The TimerService

     

    Introduced in JBoss v4.0.3, the TimerService is a simple mbean that follows

    the JBoss ServiceLifecycle model and can be used to configure an external

    javax.management.timer.Timer

    mbean, to produce periodically JMX notifications.

     

    By subscribing and reacting to those notification from a 3rd mbean, you can have

    a simple way of scheduling periodic tasks.

     

    The attributes that can be configured on the TimerService are shown below:

     

    • NotificationType: the type of the produced javax.management.timer.TimerNotification

    • NotificationMessage: the string message to put in the produced notifications

    • TimerPeriod: every how often to emit notifications, e.g. 500msec, 10sec, 5min, 1h.

      a zero value will produce just one notification

    • Repeatitions: how many timer notifications to emit when the period is not zero;

      a zero value produces infinite notifications

    • FixedRate: whether the periodic notifications should be produced at

      a FixedRate (true) or a FixedDelay (false, default) - since v4.0.5

    • TimerMBean: the ObjectName of the JMX Timer to configure; should be

      combined with a dependency.

       

    Example

     

    (taken from server/default/deploy/monitoring-service.xml)

     

    Configure a periodic 'heartbeat' timer notification to be emitted every 5 seconds.

    In this example we have inlined the creation of the Timer in the depends

    block, however, a single Timer could have been declared independently with

    multiple TimerService instances pointing to it.

      <mbean code="org.jboss.monitor.services.TimerService"
             name="jboss.monitor:name=Heartbeat,type=TimerService">
        <attribute name="NotificationType">jboss.monitor.heartbeat</attribute>
        <attribute name="NotificationMessage">JBoss is alive!</attribute>
        <attribute name="TimerPeriod">5sec</attribute>
        <depends optional-attribute-name="TimerMBean">
          <mbean code="javax.management.timer.Timer"
                 name="jboss.monitor:name=Heartbeat,type=Timer"></mbean>
        </depends>
      </mbean>
    

     

    Seeing is believing

     

    If you want to see/log the emitted notifications from the above example,

    you can configure a NotificationListener as follows. (Note we subscribe

    to the Timer mbean not the TimerService!)

      <mbean code="org.jboss.monitor.services.NotificationListener"
             name="jboss.monitor:service=NotificationListener">
        <attribute name="SubscriptionList">
          <subscription-list>
            <mbean name="jboss.monitor:name=Heartbeat,type=Timer"></mbean>
          </subscription-list>
        </attribute>
      </mbean>
    

     

    Related:

     

     

    Referenced by: