Firstly, we need to create a java class that appends the current datetime to a file.
JBatch implement two variations of Job step: Chunks - which are built around the traditional batch process of reader, processor and writer elements – and Batchlets for simple tasks.
For the simple process appending a datetime to a file we will be using a Batchlet.To correctly implement a Batchlet we must define process() and stop() methods.
Next, we need to define the steps that make-up our batch job using the Job Specification Language (JSL). The below JSL defines our single-step job and also the value of the outfile property used by the Batchlet.The JSL must be held in an XML file located in the META-INF/batch-jobs directory.
Finally, we will create an EJB to trigger our job every 30 seconds
Deploying the above will append the current datetime to the file specified in the XML at 30 second intervals:
And this is all that is required to implement the most basic batch process!
Want to learn more about JBatch? Check out Batch Applications in Java EE 7 - Undertanding JSR 352 Concepts article by Arun Gupta on the GlassFish blog; or watch the 'Batch Applications for the Java Platform 1.0' video by Chris Vignola.