Use schedulers
Schedulers enable Java EE application tasks to run at a requested time. Schedulers also enable application developers to create their own stateless session EJB components to receive event notifications during a task life cycle, allowing the plugging-in of custom logging utilities or workflow applications.
We can schedule the following types of tasks:
- Invoke a session bean method
- Send a Java Message Service (JMS) message to a queue or topic
Stateless session EJB components are also used to provide generic calendaring. Developers can either use the supplied calendar bean or create their own for their existing business calendars. For example, one of our business processes might involve invoicing for services. With the scheduler's use of stateless EJB components, we can schedule when periodic email distributions are to be sent to our customers who have received invoices. The scheduler service performs these tasks, repeating as necessary, according to the metadata for that task.
A scheduler is the mechanism by which the timer service for Enterprise Java Beans runs for persistent timers. We can configure the EJB timer service to use many of the features that schedulers provide. See the configuring a timer service information for more details. Non-persistent timers do not use the scheduler service, but they can use the work manager for the scheduler. Non-persistent timers use a work manager directly.
Use the following table to determine which persistent timer service is best for you:
Schedulers EJB timers Run stateless session EJB components and sends JMS messages Run all EJB types except for stateful session beans Persistent, transactional and highly available Persistent, transactional and highly available Tasks guaranteed to run only once Timers guaranteed to run only once, if the timer EJB uses a container-managed global transaction Run repeating tasks using any calculation rules Run repeating tasks using a repeating interval defined in milliseconds Uses a modified fixed-delay time calculation to determine repeating intervals (next run time based on the start-time of the previous task) Uses a fixed-rate time calculation to determine repeating intervals (time of the next task is based on the original scheduled time) Programmatic task monitoring capability with the use of the NotificationSink stateless session EJB component No programmatic timer monitoring Stop late or time-sensitive tasks from running Stop late or time-sensitive tasks from running (achieved through manual detection within the javax.ejb.TimedObject implementation) Manage any task lifecycle (find, suspend, resume, cancel and purge tasks programmatically and through JMX) Find and cancel its timers programmatically. Administrators find and cancel timers using a command-line utility. Store a limited amount of text with the data, like a Name (arbitrary data stored externally) Store arbitrary data with a timer This task demonstrates how to manage, develop and interoperate with schedulers and subsequent tasks.
Tasks
- Manage the scheduler service. This topic includes instructions for creating and configuring schedulers, creating and configuring a database for schedulers and administering schedulers.
- Develop and schedule tasks. This topic includes instructions for developing various types of tasks, receiving notifications from a task, submitting tasks to a scheduler, and managing tasks.
Important: Creating and manipulating scheduled tasks through the Scheduler API interface is only supported from within the Enterprise Java Beans (EJB) container or Web container (JavaServer Pages or servlets). Looking up and using a configured scheduler from a Java EE application client container is not supported.
- Interoperate with schedulers. This topic explains how to manage scheduler in a clustered environment with mixed WebSphere Application Server product versions and mixed platforms.
Subtopics
- Install default scheduler calendars
The default scheduler SIMPLE and CRON calendars are available in the SchedulerCalendars.ear system application and are automatically installed on standalone server profiles. System applications cannot be installed and uninstalled like traditional Java EE applications.- Example: Using default scheduler calendars
Use The SIMPLE and CRON calendars from any J2EE application.- Manage schedulers
Schedulers are configured using the administrative console, configuration service or scripting and are available to all servers on which a scheduler is visible.- Develop and scheduling tasks
To develop and schedule tasks, use a configured scheduler.- Scheduler daemon
A scheduler daemon is a background thread that searches for tasks to run in the database.- Scheduler calendars
The scheduler provides stateless session bean interfaces which allow creating common calendars which can be used by the scheduler and any Java EE application.
Configure a timer service Create timers using the EJB timer service for enterprise beans