Chapter 13. Timer Service

Business systems frequently use scheduling systems to run programs at specified times. Scheduling systems typically run applications that generate reports, reformat data, or do audit work at night. In other cases, scheduling systems provide callback APIs that can alert subsystems of events such as due dates, deadlines, etc. Scheduling systems often run batch jobs (a.k.a. scheduled jobs ), which perform routine work automatically at a prescribed time. Users in the Unix world frequently run scheduled jobs using cron , a simple but useful scheduling system that runs programs listed in a configuration file. Other job-scheduling systems include the OMG’s COS Timer Event Service, which is a CORBA API for timed events, as well as commercial products.

Regardless of the software, scheduling systems are used in many different scenarios:

  • In a credit card processing system, credit card charges are processed in batches so that all the charges made for an entire day are settled together instead of separately. This work is scheduled to be done in the evening to reduce the impact of processing on the system.

  • In a hospital or clinical system, Electronic Data Interface (EDI) software is used to send medical claims to various HMOs. Each HMO has its own processing requirements, but they are all routine, so jobs are scheduled to gather claim data, put it in the proper format, and transfer it to the HMO.

  • In just about any company, managers need specific reports run on a regular basis. A scheduling system can be configured to run those reports automatically and deliver them via email to managers.

Scheduling systems are also common in workflow applications, which are systems that manage document processing that typically spans days or months, and involves many systems and lots of human intervention. In workflow applications, scheduling is employed for auditing tasks that periodically take inventory of the state of an application, invoice, sales order, etc., in order to ensure everything is proceeding as scheduled. The scheduling system maintains timers and delivers events to alert applications and components when a specified date and time is reached, or when some period has expired. Here are some examples of workflow scheduling:

  • In a mortgage system, a lot of tasks have to be completed (i.e., appraisal, rate lock-in, closing appointment, etc.) before the mortgage can be closed. Timers can be set on mortgage applications to perform periodic audits that ensure everything is proceeding on schedule.

  • In a healthcare claims processing system, claims must be processed within 90 days according to terms negotiated by in-network physicians and clinics. Each claim could have a timer set to go off seven days before the deadline.

  • In a stockbroker system, buy-at-limit orders can be created for a specific number of shares, but only at a specified price or lower. These buy-at-limit orders typically have a time limit. If the stock price falls below the specified price before the time limit, the buy-at-limit order is carried out. If the stock price does not fall below the specified price before the time limit, the timer expires and the buy-at-limit order is canceled.

In the EJB world, there has been a general interest in scheduling systems that can work directly with enterprise beans. However, prior to EJB 2.1, there has been no standard J2EE scheduling system. Enterprise JavaBeans 2.1 introduces a standardized but limited scheduling system called the Timer Service.

Tip

The Java 2 Platform, Standard Edition includes the class java.util.Timer , which allows threads to schedule tasks for future execution in a background thread. This facility is useful for a variety of applications, but it’s too limited to be used in enterprise computing. Note, however, that the scheduling semantics of java.util.Timer are similar to those of the EJB Timer Service.

The Timer Service is a facility of the EJB container system that provides a timed-event API, which can be used to schedule timers for specified dates, periods, and intervals. A timer is associated with the enterprise bean that set it, and calls that bean’s ejbTimeout( ) method when it goes off. The rest of this chapter describes the EJB Timer Service API and its use with entity, stateless session, and message-driven beans, as well as providing some criticism of and suggested improvements for the Timer Service.

Titan’s Maintenance Timer

Titan Cruises has a policy of performing regular maintenance on its ships. For example, the engines require extensive and varied maintenance activities throughout the year, as does navigation equipment, communications, sewer and water systems, etc. In fact, there are literally thousands of maintenance functions to be performed on a ship throughout the year. To manage all these items, Titan uses the EJB Timer Service to alert the proper maintenance crews when an item needs to be serviced. In this chapter, we modify the Ship EJB to manage its own maintenance schedule. Titan’s Health and Safety department can use business methods on the Ship EJB to schedule and cancel maintenance items, and the Ship EJB will take care of alerting the correct maintenance crew when an item needs to be serviced.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.163.13