Java Reference
In-Depth Information
public void contextDestroyed(ServletContextEvent scEvent) {
synchronized (printerThread) {
printerThread.interrupt();
}
}
}
The addition of a formal threading framework into Java EE is much welcomed. By adhering to the use of
ManagedThreadFactory API, your enterprise applications can be made multi-threaded using an accepted standard solution.
Batch Applications for the Java Platform
The new API for batch processing provides a fine-grained experience for developers, which enables them to produce
and process batch applications in a variety of different ways. Enterprise applications no longer need to utilize
customized classes for performing batch processing, allowing enterprise applications to adhere to an adopted
standard.
There are two different approaches to creating batch applications using the API, those being “item oriented”
and “task-oriented.” Item-oriented processing is useful for those applications that require many different processes
to be combined together to formulate one job. This type of processing is also known as “chunk” processing, since
the different processes are performed in chunks. The second approach is known as task-oriented, and this type of
processing supports batch steps that are also known as batchlets.
Item-Oriented Processing
Prior to the inclusion of Batch Applications for Java EE, organizations and individuals had to write their own custom
Java implementations for processing batch jobs. Utilizing the newly added API, developers can create batch jobs using a
standard combination of XML for defining a job, and Java for programming the implementation. In the example below,
a simple batch job reads text from a file, processes it using a comparison, and then writes out the processed text. The
example batch program is simplistic, but it demonstrates how the API makes it easy to write very complex jobs.
Let's begin the explanation by taking a brief look at the API from a high level. A job consists of one or more steps,
and each step has no more than one ItemReader , ItemWriter , and ItemProcessor . A JobOperator is responsible
for launching a job, and a JobRepository is used to maintain metadata regarding the currently running job. Jobs are
defined via XML, and the <Job> element is at the root of the job definition. Thus, a <Job> is the foundational element,
which consists of one or more <step> elements, and also defines other specifics of the job such as the job name and if
it is restartable or not. Each <step> of a job consists of one or more chunks or batchlets. In this example, which covers
item-oriented processes, each step has just one chunk. To learn more about task-oriented jobs and batchlets, please
see the specification or online documentation at https://java.net/projects/jbatch/pages/Home .
As expected, each chunk of a step is defined within the XML using a <chunk> element. A <chunk> element, which
is a child of <step> , defines the reader, writer, processor pattern of a batch job. A chunk runs within the scope of a
transaction, and it is restartable at a checkpoint if it does not complete. The <reader> element is a child element of
<chunk> , and it is used to specify the reader for that chunk. The <reader> element can accept zero or more name/
value pair properties using a <properties> element. The <processor> element is also a child element of <chunk> ,
which specifies the processor element for that chunk. Like a <reader> element, a <processor> element can accept
zero or more name/value pair properties using a <properties> element. The <writer> element is a child element
of <chunk> as well, which specifies the writer for the chunk step. Again, like the reader and processor, the <writer>
element can accept zero or more name/value pair properties using a <properties> element.
The XML configuration for a job resides in an XML file that should be named similar to the batch job to which it
belongs. This file should reside within a folder named batch-jobs , which in turn resides in the application META-INF folder.
An XML file named batch.xml should also reside within the META-INF folder. This file contains the mapping for the item
reader, writer, and processor elements using <ref> elements and mapping the item names to a Java implementation class.
 
Search WWH ::




Custom Search