Expresso Job Control

The Job Handler component is a server-side thread (can also be run in a seperate VM if desired) that runs tasks according to entries in a job queue. These jobs may be run sequentially (single threaded) or in parallel (multi threaded), depending on the nature of the job.

Version:

Expresso 5.0

Author:

Michael Nash

Expresso Components Listing


Caching Configuration Values Controller Objects
Database Objects DB Connection Pooling Email Connectivity
Event Notification and Error Handling Health Check Job Control
Logging Registration & Login Security
Taglibs Unit Testing Workflow
XML


Introduction

As a server side process, a job can be queued by means of a user request (by a servlet) or by means of a simple batch file, which can be triggered by an operating system scheduler to provide scheduled jobs - for example a certain job to run a report might be triggered every night at 10PM. Jobs typically send notice of their results via the event mechanism, and system error events are automatically triggered if a problem occurs.

Jobs are submitted to the queue either by:

  • user interaction (e.g. manually requesting a job)
  • timed processes (e.g. cron or NT scheduler)
  • or by other jobs (such as events triggering a data load or report run).
Job control is similar to the same mechanism used so successfully on mainframes for many years. It can be used for any function which takes more time than is practical for an interactive session, such as a complex calculation, a data load from a legacy system, or the running of a group of long reports or analyses.

Topics

Introduction
Job Queue
Job Handler
Job Order
Job Scheduling
Conclusion

Job Queue

The basic mechanism involved is a "job queue". A job is queued by creating a new entry in the job queue and marking it as "available". A job can also have parameters associated with it to control it's functions, much like arguments to a method.

Job Handler

There are one or more "job handler" objects running on the server side, waiting for jobs to enter the queue - when they do, a job handler picks up the job & begins to process it - which job handler does this can be controller so that different jobs run on different systems, for performance reasons if so desired. Each job handler may process either a single job or can run a set number of jobs in parallel, and each job can be designated as "single-threaded" (e.g. should not be run in parallel with other jobs) or "multi-threaded".

The job-handler objects can also be implemented as either stateful or stateless Session EJB's, allowing business logic to be developed with all of the advantages of Enterprise JavaBeans.

The Job Handler is a separate thread (which can be run as a thread in your application/servlet server JVM, or as a separate Java application (not a servlet)) that runs on a server system (usually the same system as your servlet or application server, but not necessarily). The Job Handler constantly monitors the Job Queue, and when Jobs are detected it starts the requested job, monitor's it's processing, and sends email notifications when it is complete. This allows your application to request tasks that would take longer than a few moments as a background job.

Starting the Job Handler

Normally the JobHandler is run as a separate thread in your application server's JVM by adding the 'startJobHandler=y' property to your default.properties (or other property) file.

In order to start the Job Handler in a seperate JVM, you must issue a command line on your server system. It is almost always convenient to package up this command line into a batch or shell script file (depending on your operating system), so that it can be run again easily.

An example Job Handler shell script is shown here (the text is all one line in the shell script, but broken into multiple lines here for readability):

/usr/java/jdk1.2.2/bin/java -classpath /usr/orion/orion/orion.jar:/usr/java/lib/mail.jar:/usr/java/lib/activation.jar:/usr/java/lib:/usr/java/jdk1.2.2/lib/tools.jar com.jcorporate.expresso.core.utility.JobHandler configDir=/usr/expresso/config webAppDir=/usr/web-apps/expresso

This example uses the JDK1.2.2 runtime and the servlet API libraries in the Orion Application Server, assumes that "default.properties" is in the specified configDir directory. Running this script produces output to the standard output, so it is recommended that it be run with the nohup command, or that it's output be redirected.

This script can of course be altered for the specific directories and libraries that you are using, and broken into multiple lines if desired.

The Job Handler is ordinarily left running whenever the server is up, so that Jobs receive immediate consideration based on their priorities.

Please see the Operation page for information about queueing a test job to verify that the Job Handler is fully operational. You can now continue with the Setup page.

Job Order

Jobs are handled in priority order, and a job can be suspended and it's priority changed even once it has begun running. Certain jobs can be set to process at only specified times, deferring process-intensive tasks until off-peak hours if so desired.

Jobs frequently trigger event notifications when they are complete or when problems occur.

Job Scheduling Features

Submit new job

  1. // allocate empty slot for new job
  2. JobQueue oneJob = new JobQueue();
  3. // this job should be executed on "Unix" systems Only.
  4. // the valid options are: MSWIN, Unix, any or Specific OS as returned by System.getProperty("java.os")
  5. oneJob.setJobOSName("Unix");
  6. // execute this job at specified by cron parameters time.
  7. oneJob.setJobCronParams(minute, hour, dayOfMonth, month, dayOfWeek, year);
  8. // set job code to execute
  9. oneJob.setJobCode("com.jcorporate.expresso.utils.TestJob");
  10. // set the owner of this job
  11. oneJob.setUserName("root")
  12. // job is ready for execution
  13. oneJob.setJobStatus(JobQueue.JOB_STATUS_AVAILABLE)
  14. // Add parameters associated with this job (same as before)
  15. // submit job
  16. oneJob.add();

Controlling jobs

  1. JobHandlerControl jobControl = new JobHandlerControl();
  2. String jobID = "10";
  3. // stop job
  4. jobControl.setCmdStopJob(jobID);
  5. jobControl.add();
  6. // restart job
  7. jobControl.setCmdRestartJob(jobID);
  8. jobControl.add();

Job Scheduling Parameters

The setJobCronParams method can accept the following values for it's parameters:

minute minute of the alarm. Allowed values 0-59.
hour hour of the alarm. Allowed values 0-23.
dayOfMonth day of month of the alarm (-1 if every day). This attribute is exclusive with dayOfWeek. Allowed values 1-31. java.util.Calendar constants can be used.
month month of the alarm (-1 if every month). Allowed values 0-11 (0 = January, 1 = February, ...). java.util.Calendar constants can be used.
dayOfWeek day of week of the alarm (-1 if every day). This attribute is exclusive with dayOfMonth.Allowed values 1-7 (1 = Sunday, 2 = Monday, ...).
year year of the alarm. When this field is not set (i.e. -1) the alarm is repetitive (i.e. it is rescheduled when reached).

Conclusion

For technical information about how to use Job Control, please refer to the Expresso Developers Guide (EDG) or the Javadocs.

Top of Page


Home | Products | Services | Partners | Customers | About Us | Login | Forums | Contact Us

Copyright © 2001-2002 Jcorporate Ltd. All rights reserved. Copyright Privacy

Last Modified: 07-Oct-02 9:43:59 PM