Before you begin
This task assumes that you have already configured a scheduler instance using the administrative console.Why and when to perform this task
Once you have developed a TaskInfo object that contains all relevant data for a task, submit the task to a scheduler instance for creation. For example:
//lookup the scheduler instance to be used Scheduler scheduler = (Scheduler)new InitialContext.lookup("java:comp/env/Scheduler"); TaskStatus status = scheduler.create(taskInfo);
You
must plan ahead when you create tasks with the Scheduler. When the Scheduler
creates a task, the security context of the creator is stored with the scheduled
task. When the task is later completed, the original context
is reapplied to the thread before calling the customer TaskInfo instance.
If you intend to secure your application using the global security mechanism
built into WebSphere Application Server, create each task with the correct
credentials on the thread. Once each task has the correct credentials, you
can disable and re-enable security without causing any security problems.
If you do not set the security context when the Scheduler task is created
and you later enable security in the target application, a security exception
or error message might display.
The security context
is not set if any of the follow conditions are true:
If any of the previously mentioned conditions
are true when you create your task and you need to enable security on your
application server or application, you must complete the following steps:
When you configure a scheduler, it is bound to a global JNDI name. Although the desired scheduler instance can be found by performing a lookup on that JNDI name, it is better to create a resource reference, which allows for more flexibility in configuring the scheduler.
Note: The scheduler interface is a local interface. It can only be used by server-side code; that is, J2EE applications.
Once the call to the create() method is complete, the task exists in the persistent store and is run at the time specified in the TaskInfo object. This call is transactional. If a transactional context is present on the thread when the create() method rolls back or is aborted, the task does not run.
The status object, which has been returned by the call to the create() method, contains information about the state of the task, as well as the task ID. The task ID is the unique identifier for this task, and is required if the task is to be suspended, resumed, cancelled, and so on, at a later time.
Note: The status object is only a snapshot of the current state of the task. Use the Scheduler.getStatus() method to receive the current state when needed.