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 call a method on a task handler session bean using the BeanTaskInfo implementation.
Steps for this task
//lookup the scheduler instance to be used Scheduler scheduler = (Scheduler)new InitialContext.lookup("java:comp/env/Scheduler"); BeanTaskInfo taskInfo = (BeanTaskInfo) scheduler.createTaskInfo(BeanTaskInfo.class)
Note: Creating a BeanTaskInfo 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 you can use 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); //find the session bean to be called when the task executes Object o = new InitialContext().lookup("java:comp/env/ejb/MyTaskHandlerHome"); TaskHandlerHome home = (TaskHandlerHome)javax.rmi.PortableRemoteObject.narrow(o,TaskHandlerHome.class); //now set the start time and task handler to be called in the task info taskInfo.setTaskHandler(home); 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.