<<

Implementing Batch Processing in Java EE 7 Ivar Grimstad

Batch - JavaLand 2014 @ivar_grimstad About

Ivar Grimstad

@ivar_grimstad

Batch - JavaLand 2014 @ivar_grimstad batch (plural batches) The quantity of bread or other baked goods baked one time. We made a batch of cookies to take to the party.

Source: http://en.wiktionary.org/wiki/batch

Batch - JavaLand 2014 @ivar_grimstad Content

• Batch Applications • Batch in Java EE 7 • Demo • Wrap-Up

Batch - JavaLand 2014 @ivar_grimstad History

Batch - JavaLand 2014 @ivar_grimstad Batch Applications

Batch - JavaLand 2014 @ivar_grimstad Common Usages

• Bulk updates • Image processing • Conversions

Batch - JavaLand 2014 @ivar_grimstad Advantages of Batch Processing

• No User Interaction • Utilize Batch Windows • Repetitive Work

Batch - JavaLand 2014 @ivar_grimstad Disadvantages of Batch Processing

• Training • Difficult Debugging • Costly

Batch - JavaLand 2014 @ivar_grimstad To The Rescue

Batch Frameworks

Batch - JavaLand 2014 @ivar_grimstad Batch Frameworks

• Jobs, steps, decision elements, relationships • Parallel or sequential processing • State • Launch, pause and resume • Error handling

Batch - JavaLand 2014 @ivar_grimstad Requirements of Batch Applications

Large Data Volume Automation Robustness Reliability Performance

Batch - JavaLand 2014 @ivar_grimstad Batch Processing in Java EE 7

Batch - JavaLand 2014 @ivar_grimstad The Batch Processing Framework

• Batch Runtime • Specification • Java API – Runtime interaction – Implementation

Batch - JavaLand 2014 @ivar_grimstad Batch Runtime

• Start jobs

• Check status of jobs

Batch - JavaLand 2014 @ivar_grimstad Job Specification

• Steps • Flows • Splits • Decision Elements

Batch - JavaLand 2014 @ivar_grimstad Job Specification Language (JSL) ... ... ... ... ...

Batch - JavaLand 2014 @ivar_grimstad Java Batch API (task oriented)

Package Interface Description Implements the business logic of a task-oriented javax.batch.api Batchlet step.

Batch - JavaLand 2014 @ivar_grimstad Java Batch API (chunk oriented)

Package Interface Description Reads items from an input source in a javax.batch.api.chunk ItemReader chunk step. Processes input items to obtain output javax.batch.api.chunk ItemProcessor items in chunk steps. javax.batch.api.chunk ItemWriter Writes output items in chunk steps.

Batch - JavaLand 2014 @ivar_grimstad Chunk Oriented Steps

ItemReaderItem ItemProcessor ItemWriter

Batch - JavaLand 2014 @ivar_grimstad Dependency Injection

@Dependent @Named("MyItemReader") public class MyItemReaderImpl implements ItemReader { }

...

Batch - JavaLand 2014 @ivar_grimstad Batch Runtime API

@Dependent @Named("MyItemReader") public class MyItemReaderImpl implements ItemReader {

@Inject JobContext jobCtx;

@Inject StepContext stepCtx; }

Batch - JavaLand 2014 @ivar_grimstad Invocation

EJB, Servlet, ManagedBean etc.

jobOperator = BatchRuntime.getJobOperator(); Properties props = new Properties(); props.setProperty("parameter1", "value1");

long execID = jobOperator.start("simplejob", props);

Batch - JavaLand 2014 @ivar_grimstad Packaging

• No separate packaging needed • Can be included in any Java EE application

– META-INF/batch-jobs/ – WEB-INF/classes/META-INF/batch-jobs/

Batch - JavaLand 2014 @ivar_grimstad Monitoring

Package Interface Description Provides methods to obtain information javax.batch.runtime JobExecution about submitted jobs.

JobExecution jobExec = jobOperator.getJobExection(id); String status = jobExec.getBatchStatus().toString();

Batch - JavaLand 2014 @ivar_grimstad Creating a Java EE Batch Application

• Design the application • Create batch artifacts • Define jobs, steps and execution flow • Launch batch application

Batch - JavaLand 2014 @ivar_grimstad DEMO

Batch - JavaLand 2014 @ivar_grimstad Demo Steps

• Create a simple batchlet • Create a simple chunk oriented job • Package in a WAR • Start jobs from a Servlet • Schedule jobs from Timer EJB

Batch - JavaLand 2014 @ivar_grimstad Simple Batchlet

Batch - JavaLand 2014 @ivar_grimstad Simple Chunk Oriented

Batch - JavaLand 2014 @ivar_grimstad Demo Steps (what we did)

• 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

Batch - JavaLand 2014 @ivar_grimstad Summary

Batch - JavaLand 2014 @ivar_grimstad …but isn’t it?

Batch - JavaLand 2014 @ivar_grimstad Summary

• Simple and Flexible • Clear and precise API • No separate packaging required • Is a part of Java EE

Batch - JavaLand 2014 @ivar_grimstad Sources

https://github.com/ivargrimstad/javaee-batch

Batch - JavaLand 2014 @ivar_grimstad Batch - JavaLand 2014 @ivar_grimstad