When creating a scheduler (org.jboss.varia.scheduler.Scheduler), it is important to know if the Timer (javax.management.timer.Timer) service has already been started. If it has not been started, the scheduler will automatically create one for you. However, if you redeploy your scheduler, the Timer that was previously started will maintain the class loader associated with the previously deployed scheduler. This will cause problems with the newly deployed scheduler. You need to do one of the following:
1. Create a service xml deployment with the timer service and deploy it seperate. For example, create a timer-service.xml that contains:
<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="javax.management.timer.Timer" name="jboss:service=Timer"/> </server>
2. Add a depends tag to your scheduler for the timer. For example:
<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.jboss.varia.scheduler.Scheduler" name="acme:service=Scheduler"> <attribute name="StartAtStartup">true</attribute> <attribute name="SchedulableClass">com.acme.MySchedulable</attribute> <attribute name="InitialStartDate">NOW</attribute> <attribute name="SchedulePeriod">5000</attribute> <attribute name="InitialRepetitions">-1</attribute> <depends> <mbean code="javax.management.timer.Timer" name="jboss:service=Timer"/> </depends> </mbean> </server>
It is important to note that unless otherwise specified (or it already exits), the scheduler will start the Timer service with an object name of 'jboss:service=Timer' by default. If you want to use a different object name for the Timer service that the scheduler will start, will need to declare in a attribute named 'TimerName'.
If your scheduler happens to depend on another mbean, it is probably necessary for that mbean to be already created. For example, if your scheduler depends on the System Properties service, you would need to specify the name of the service in a depends tag:
<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.jboss.varia.scheduler.Scheduler" name="acme:service=Scheduler"> <attribute name="StartAtStartup">true</attribute> <attribute name="SchedulableClass">com.acme.MySchedulable</attribute> <attribute name="InitialStartDate">NOW</attribute> <attribute name="SchedulePeriod">5000</attribute> <attribute name="InitialRepetitions">-1</attribute> <depends>jboss:type=Service,name=SystemProperties</depends> </mbean> </server>
The first example has an mbean tag nested inside the depends tag. This is so the scheduler service will start the Timer service. If you need the service to be independent of the scheduler you are trying to create, then you need to reference the name of that service and not use a nested mbean tag.
Comments