implementing batch processing in java ee 7 2014...batch - javaland 2014 @ivar_grimstad implementing...
TRANSCRIPT
Batch - JavaLand 2014 @ivar_grimstad
Implementing Batch Processing in Java EE 7Ivar Grimstad
Ivar Grimstad
About
Batch - JavaLand 2014 @ivar_grimstad
@ivar_grimstad
batch (plural batches)
The quantity of bread or other baked goods baked at one time.
We made a batch of cookies to take to the party.
Batch - JavaLand 2014 @ivar_grimstad
Source: http://en.wiktionary.org/wiki/batch
• Batch Applications
• Batch in Java EE 7
• Demo
• Wrap-Up
Content
Batch - JavaLand 2014 @ivar_grimstad
History
Batch - JavaLand 2014 @ivar_grimstad
Batch Applications
Batch - JavaLand 2014 @ivar_grimstad
• Bulk database updates
• Image processing
• Conversions
Common Usages
Batch - JavaLand 2014 @ivar_grimstad
• No User Interaction
• Utilize Batch Windows
• Repetitive Work
Advantages of Batch Processing
Batch - JavaLand 2014 @ivar_grimstad
• Training
• Difficult Debugging
• Costly
Disadvantages of Batch Processing
Batch - JavaLand 2014 @ivar_grimstad
Batch Frameworks
To The Rescue
Batch - JavaLand 2014 @ivar_grimstad
• Jobs, steps, decision elements, relationships
• Parallel or sequential processing
• State
• Launch, pause and resume
• Error handling
Batch Frameworks
Batch - JavaLand 2014 @ivar_grimstad
Large Data Volume
Automation
Robustness
Reliability
Performance
Requirements of Batch Applications
Batch - JavaLand 2014 @ivar_grimstad
Batch - JavaLand 2014 @ivar_grimstad
Batch Processing in Java EE 7
• Batch Runtime
• Job Specification
• Java API
–Runtime interaction
– Implementation
The Batch Processing Framework
Batch - JavaLand 2014 @ivar_grimstad
• Start jobs
• Check status of jobs
Batch Runtime
Batch - JavaLand 2014 @ivar_grimstad
• Steps
• Flows
• Splits
• Decision Elements
Job Specification
Batch - JavaLand 2014 @ivar_grimstad
Job Specification Language (JSL)
Batch - JavaLand 2014 @ivar_grimstad
<job>
<listeners>
<listener />
</listeners>
<properties>
<property />
</properties>
<step ...> ... </step>
<step ...> ... </step>
<decision ...> ... </decision>
<flow ...> ... </flow>
<split ...> ... </split>
</job>
Java Batch API (task oriented)
Batch - JavaLand 2014 @ivar_grimstad
Package Interface Description
javax.batch.api BatchletImplements the business logic of a task-oriented
step.
Java Batch API (chunk oriented)
Batch - JavaLand 2014 @ivar_grimstad
Package Interface Description
javax.batch.api.chunk ItemReaderReads items from an input source in a
chunk step.
javax.batch.api.chunk ItemProcessorProcesses input items to obtain output
items in chunk steps.
javax.batch.api.chunk ItemWriter Writes output items in chunk steps.
ItemReader ItemWriterItemProcessor
Chunk Oriented Steps
Batch - JavaLand 2014 @ivar_grimstad
Item
Dependency Injection
Batch - JavaLand 2014 @ivar_grimstad
@Dependent
@Named("MyItemReader")
public class MyItemReaderImpl implements ItemReader {
}
<step id="stepA" next="stepB">
<chunk>
<reader ref="MyItemReader"></reader>
...
</chunk>
</step>
Batch Runtime API
Batch - JavaLand 2014 @ivar_grimstad
@Dependent
@Named("MyItemReader")
public class MyItemReaderImpl implements ItemReader {
@Inject
JobContext jobCtx;
@Inject
StepContext stepCtx;
}
Invocation
Batch - JavaLand 2014 @ivar_grimstad
jobOperator = BatchRuntime.getJobOperator();
Properties props = new Properties();
props.setProperty("parameter1", "value1");
long execID = jobOperator.start("simplejob", props);
EJB, Servlet, ManagedBean etc.
• No separate packaging needed
• Can be included in any Java EE application
–META-INF/batch-jobs/
–WEB-INF/classes/META-INF/batch-jobs/
Packaging
Batch - JavaLand 2014 @ivar_grimstad
Monitoring
Batch - JavaLand 2014 @ivar_grimstad
Package Interface Description
javax.batch.runtime JobExecutionProvides methods to obtain information
about submitted jobs.
JobExecution jobExec = jobOperator.getJobExection(id);
String status = jobExec.getBatchStatus().toString();
• Design the application
• Create batch artifacts
• Define jobs, steps and execution flow
• Launch batch application
Creating a Java EE Batch Application
Batch - JavaLand 2014 @ivar_grimstad
Batch - JavaLand 2014 @ivar_grimstad
DEMO
• Create a simple batchlet
• Create a simple chunk oriented job
• Package in a WAR
• Start jobs from a Servlet
• Schedule jobs from Timer EJB
Demo Steps
Batch - JavaLand 2014 @ivar_grimstad
Simple Batchlet
Batch - JavaLand 2014 @ivar_grimstad
Simple Chunk Oriented
Batch - JavaLand 2014 @ivar_grimstad
• Created a simple batchlet
• Created a simple chunk oriented job
• Packaged application in a WAR
• Started jobs from a Servlet
• Scheduled jobs from Timer EJB
Demo Steps (what we did)
Batch - JavaLand 2014 @ivar_grimstad
Batch - JavaLand 2014 @ivar_grimstad
Summary
…but isn’t it?
Batch - JavaLand 2014 @ivar_grimstad
• Simple and Flexible
• Clear and precise API
• No separate packaging required
• Is a part of Java EE
Summary
Batch - JavaLand 2014 @ivar_grimstad
https://github.com/ivargrimstad/javaee-batch
Sources
Batch - JavaLand 2014 @ivar_grimstad
Batch - JavaLand 2014 @ivar_grimstad