[Version 5.0.1 and later]Submitting a task to a scheduler

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);

[Version 5.0.1]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.

[Version 5.0.1]The security context is not set if any of the follow conditions are true:

[Version 5.0.1]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:

  1. Cancel the task with security disabled
  2. Recreate each scheduled task with security enabled, which enables the scheduler to store the desired security context with the task.

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.


Related concepts
Transactions and the scheduler service
Asynchronous beans
Related tasks
Developing a task that calls a session bean
Developing a task that sends a JMS message
Configuring a scheduler
Creating a scheduler resource reference



Searchable topic ID:   tsch_submittask
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/scheduler/tasks/tsch_submittask.html

Library | Support | Terms of Use | Feedback