Why and when to perform this task
The scheduler API supports different implementations of the TaskInfo interface, each of which can be used to schedule a particular type of work. This topic describes how to use the MessageTaskInfo implementation, which sends a JMS message to either a queue or a topic.
Steps for this task
//lookup the scheduler instance to be used Scheduler scheduler = (Scheduler)new InitialContext.lookup("java:comp/env/Scheduler"); MessageTaskInfo taskInfo = (MessageTaskInfo) scheduler.createTaskInfo(MessageTaskInfo.class);
Note: Creating a MessageTaskInfo object does not add the task to the persistent store. Rather, it creates a placeholder for the necessary data. The task is not added to the persistent store until the create() method is called on a Scheduler instance, as described in the topic Submitting a task to a scheduler.
The TaskInfo interface contains various set() methods that can be used to control execution of the task, including when the task will fire and what work the task will do when it fires. For example:
//create a date object which represents 30 seconds from now java.util.Date startDate = new java.util.Date(System.currentTimeMillis()+30000); //now set the start time and the JNDI names for the queue connection factory and the queue taskInfo.setConnectionFactoryJndiName("jms/MyQueueConnectionFactory"); taskInfo.setDestination("jms/MyQueue"); taskInfo.setStartTime(startDate);
The TaskInfo interface specifies additional control points, as documented in Javadoc.
Results
A TaskInfo object has been created that contains all of the relevant data for a task.What to do next
Submit the task to a scheduler instance for creation, as described in the topic Submitting a task to a scheduler.