Java Reference
In-Depth Information
Chapter12.Long-term Tasks' Execution
So far, our applications focused on interaction with the user. This may be the most import-
ant aspect of your future projects, but there are some scenarios that require a different ap-
proach. Maintenance tasks, importing big sets of data or time-consuming computations are
usually addressed in a batch mode instead of an interactive manner. Often, these kinds of
jobs are not part of the standard operations and should be invoked only when the server
load is at its lowest or periodical.
Before Java EE 7, there was no standardized way to implement batch jobs (operations that
do not require user interaction). The deal changed with JSR 352 ( https://jcp.org/en/jsr/de-
tail?id=352 ) and the introduction of the batch framework, which uses an XML language to
define jobs.
When it comes to processor-intensive tasks, the natural way is to think about paralleliza-
tion. Modern CPUs have multiple cores, which can be easily utilized by the JVM. The only
problem is that in Java EE, using concurrency primitives known from Java SE is discour-
aged. The programmer may impair the stability and availability of the whole container.
Once more, the new JSR 236 ( https://jcp.org/en/jsr/detail?id=236 ) provides new ways to
overcome this architectural obstacle. The new specification ManagedExecutorSer-
vice is a container-aware version of ExecutorService known from Java SE.
In this chapter, we will cover the following topics:
• How to create and execute batch jobs
• What are the differences between different batch job types
• How to create our custom worker threads inside a Java EE container
Search WWH ::




Custom Search