{{parent page="Jboss"}} ===Scheduling tasks on jboss=== Jboss comes with a scheduler. I'm not familiar with the terms so it's hard to provide a highlevel description. The following example works on jboss-4.3.2-GA ===Create a Scheduler class=== Nothing too fancy here, it implements the jboss Schedulable class, and writes a log whenever the perform() is called. This class file needs to be packaged as a jar file, and saved to the default/deploy/lib directory under jboss so jboss is able to access it on startup. %%(java;MyTask.java) import java.util.Date; import org.jboss.varia.scheduler.Schedulable; import org.apache.log4j.Logger; public class MyTask implements Schedulable { private static final Logger log = Logger.getLogger(MyTask.class); private String name; private long value; public MyTask(String name, long value) { this.name = name; this.value = value; log.info("constructor name: " + name + ", value: " + value); } public void perform(Date now, long remainingRepetitions) { log.info("perform, now: " + now + ", remainingRepetitions: " + remainingRepetitions + ", name: " + name + ", value: " + value); } } %% ===Deploy the scheduler service=== In jboss's deploy directory, create a service.xml file, let's just call it myscehduler-service.xml. The Timer mbean is needed for every scheduler. If you plan on implementing more than 1 scheduler, you need another Timer mbean. The second mbean calls the MyTask scheduler. It also tell the scheduler when to start and how often it should be waken. %%(xml;myscheduler-service.xml) true true true MyTask TaskFoo,123456789 java.lang.String,long NOW 60000 -1 %% ===Start jboss=== That's it. Once you have the jar file and xml file in place, you should start seeing these messages in server.log: %% 21:22:55,083 INFO [MyTask] perform, now: Thu Feb 25 21:22:55 HKT 2010, remainingRepetitions: -1, name: TaskFoo, value: 123456789 21:23:55,083 INFO [MyTask] perform, now: Thu Feb 25 21:23:55 HKT 2010, remainingRepetitions: -1, name: TaskFoo, value: 123456789 21:24:55,084 INFO [MyTask] perform, now: Thu Feb 25 21:24:55 HKT 2010, remainingRepetitions: -1, name: TaskFoo, value: 123456789 %%