WAS v8.5 > Develop applications > Develop Scheduler service

Develop and schedule tasks

To develop and schedule tasks, use a configured scheduler.

  1. Look up a configured scheduler. Refer to the Accessing schedules topic. Each configured scheduler is available from two different programming models:

    • A Java EE server application, such as a servlet or EJB component, can use the Scheduler API. Schedulers are accessed by looking them up using a JNDI name or resource reference.
    • JMX applications, such as wsadmin scripts, can use the Scheduler API using WASScheduler MBeans.

  2. Develop the task.

    The Scheduler API supports different implementations of the TaskInfo interface, each of which can be used to schedule a particular type of work. Refer to the Developing a task that calls a session bean topic and Develop a task that sends a JMS message topic for details. The task object referenced in the Develop a task that sends a JMS message topic can send a JMS message to either a queue or a topic.

    Creating and manipulating scheduled tasks through the Scheduler interface is only supported from within the EJB container or Web container (Enterprise beans or servlets). Looking up and using a configured scheduler from a Java EE application client container is not supported.

  3. Receive scheduler notifications. A notification sink is set on a task in order to receive the notification events that are generated by a scheduler when it performs an operation on the task.

  4. Use custom calendars. We can assign a UserCalendar session bean to a task that allows schedulers to use custom and predefined date algorithms to determine when a task should run. Refer to the UserCalendar interface topic for details.
  5. Submit tasks to a scheduler. After a TaskInfo object has been created, it can be submitted to the scheduler for task creation by calling the Scheduler.create() method.
  6. Manage tasks with a scheduler.
  7. Secure tasks with a scheduler.


Example

We can use the SIMPLE and CRON calendars from any Java EE application. This example illustrates the process.


Use default scheduler calendars. The following code examples illustrates how to use connections correctly and incorrectly.

Use default scheduler calendars involves looking up the default UserCalendarHome EJB home object, creating the UserCalendar bean and calling the applyDelta() method. For details on the applyDelta method as well as the syntax for the SIMPLE and CRON calendars, see UserCalendar interface topic.

import java.util.Date;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import com.ibm.websphere.scheduler.UserCalendar;
import com.ibm.websphere.scheduler.UserCalendarHome;

// Create an initial context InitialContext ctx = new InitialContext();

// Lookup and narrow the default UserCalendar home.
UserCalendarHome defaultCalHome=(UserCalendarHome)
 PortableRemoteObject.narrow(ctx.lookup(
      UserCalendarHome.DEFAULT_CALENDAR_JNDI_NAME), 
    UserCalendarHome.class);

// Create the default UserCalendar instance.
UserCalendar defaultCal = defaultCalHome.create();

// Calculate a date using CRON based on the current // date and time.  Return the next date that is 
// Saturday at 2AM
Date newDate = 
    defaultCal.applyDelta(new Date(), 
        "CRON", "0 0 2 ? * SAT");


Subtopics


Related


Manage schedulers


Reference:

MBean API documentation
UserCalendar interface


+

Search Tips   |   Advanced Search