Batching and Java EE
(jdk.io)
What is Batch Processing?
Batch jobs are typically:
- Bulk oriented
- Non interactive
- Potentially compute intensive
- May require parallel execution
- Maybe invoked, ad hoc, scheduled, on-demand etc.
Batching Examples
- Monthly reports/statements
- Daily data cleanup
- One-time data migrations
- Data synchronization
- Data analysis
- Portfolio rebalancing
Introducing Java EE Batching
- Introduced in Java EE 7
- JSR 352 - https://jscp.org/en/jsr/detail?id=352
- Reference implementation:
https://github.com/WASdev/standards.jsr352.jbatch
- Batch Framework:
- Batch container for execution of jobs
- XML Job Specification Language
- Batch annotations and interfaces
- Supporting classes and interfaces for interacting with the container
- Depends on CDI
Java EE Batching Overview
Java EE Batching Overview
Java EE Batching Features
- Fault-tolerant – checkpoints and job persistence
- Transactions – chunks execute within a JTA transaction
- Listeners – notification of job status/completion/etc.
- Resource management – limits concurrent jobs
- Starting/stopping/restarting – job control API
Java EE Batching Deployment
Deploy batch jobs in:
Manage jobs – split application into modules
Batchlet
@Named @Dependent
public class SimpleBatchlet extends AbstractBatchlet {
private static final LOGGER = Logger.getLogger(“SimpleBatchlet”);
@Override
public String process() throws Exception {
LOGGER.info(“Executed a simple bacthlet!”);
return BatchStatus.COMPLETED.toString();
}
}
Exit Codes
Code Description
STARTING Job has been submitted to runtime.
STARTED Batch job has started executing.
STOPPING Job termination has been requested.
STOPPED Job has been stopped.
FAILED Job has thrown an error or failure triggered by <failure>
COMPLETED Job has completed normally.
ABANDONDED Job cannot be restarted
Basic Layout
Job Configuration
META-INF/batch-jobs/<job-name>.xml
<?xml version=”1.0” encoding=”UTF-8”?>