Java EE 7 Batch processing in the Real World

Roberto Cortez
Roberto CortezJava EE Senior Software Engineer at Tomitribe
Java 
EE 
7 
Batch 
Processing 
in 
the 
Real 
World 
Roberto 
Cortez 
& 
Ivan 
St. 
Ivanov 
JavaOne 
2014 
#CON2818
Who 
are 
we? 
Roberto 
Cortez 
@radcortez 
h/p://www.radcortez.com 
Freelancer, 
Speaker, 
RebelLabs 
Author, 
Blogger 
Ivan 
St. 
Ivanov 
@ivan_stefanov 
h/p://nosoGskills.com 
Architect, 
SAP 
Labs 
Bulgaria, 
JBoss 
Forge 
contributor
QuesHons? 
As 
soon 
as 
you 
have 
them!
What 
is 
Batch? 
“A 
group 
of 
records 
processed 
as 
a 
single 
unit, 
usually 
without 
input 
from 
a 
user.” 
(from 
Google)
Why 
Batch? 
(Computers) 
• Make 
use 
of 
idle 
resources 
• ShiT 
the 
Hme 
of 
processing 
• Manage 
large 
repeated 
work 
easily 
• Shared 
by 
mulHple 
users
Batch 
is 
in 
our 
lives 
• By 
paying 
bills 
• On 
the 
grocery 
• In 
traffic 
• Cooking 
food
Why 
Batch? 
(General) 
• Efficiency 
• Focus 
on 
a 
single 
problem 
• Avoid 
context 
switch 
• Reduce 
costs
State 
of 
the 
Art 
• Spring 
Batch 
• IBM 
Websphere 
• Hadoop 
• Java 
SE, 
Scheduler, 
in-­‐house 
frameworks
The 
JSR-­‐352 
• Batch 
ApplicaHons 
for 
the 
Java 
pla]orm 
• Heavily 
inspired 
by 
Spring 
Batch 
• Available 
since 
Java 
EE 
7 
• Also 
designed 
for 
Java 
SE
The 
JSR-­‐352 
Features 
• Task 
and 
Chunk 
oriented 
processing 
• SequenHal 
and/or 
Parallel 
execuHon 
• CheckpoinHng 
• Workflow 
• Stop 
and 
restart 
• ExcepHon 
handling
Batch 
Domain 
Language 
Job 
Operator 
Job 
Step 
Job 
Repository 
Item 
Reader 
Item 
Processor 
Item 
Writer 
1 
*
Job 
composiYon 
* 
Job 
Step 
* 
JobInstance 
* 
* 
* 
JobExecuYon 
StepExecuYon
Java 
EE 
Batch 
API
Batchlet 
DefiniYon 
@Named 
public 
class 
MyBatchlet 
extends 
AbstractBatchlet 
{ 
@Override 
public 
String 
process() 
{ 
System.out.println("Running 
inside 
a 
batchlet"); 
return 
BatchStatus.COMPLETED.toString(); 
} 
}
Job 
SpecificaYon 
Language 
<job 
id="myFirstBatch"> 
<step 
id="myStep" 
> 
<batchlet 
ref="myBatchlet"/> 
</step> 
</job>
Start 
the 
Job 
JobOperator 
jobOperator 
= 
BatchRunYme.getJobOperator(); 
Long 
execuYonId 
= 
jobOperator.start("myJob", 
new 
ProperYes()); 
JobExecuYon 
jobExecuYon 
= 
jobOperator.getJobExecuYon(execuYonId);
Batchlet 
• Task 
oriented 
Batch 
Step 
• Suitable 
for 
• Short 
execuHons 
• Handle 
system 
resources 
• IniHalizaHon 
and 
Cleanup
Chunk 
• ETL 
style 
(Reader, 
Processor, 
Writer) 
• Suitable 
for 
• Handle 
large 
amounts 
of 
data 
• Failover 
safety 
(checkpoint) 
• Long 
running 
applicaHons
Chunk 
Processing 
Step 
ItemReader 
ItemProcessor 
ItemWriter 
read() 
read() 
process(item) 
process(item) 
write(items) 
item 
item 
item 
item 
execute() 
ExitStatus
Defining 
Chunk 
Step 
<step 
id="myChunk"> 
<chunk 
checkpoint-­‐policy="item" 
item-­‐count="3"> 
<reader 
ref=“myItemReader"/> 
<processor 
ref=“myItemProcessor"/> 
<writer 
ref=“myItemWriter"/> 
</chunk> 
</step>
Item 
Reader 
@Named 
public 
class 
MyItemReader 
extends 
AbstractItemReader 
{ 
public 
Object 
readItem() 
throws 
ExcepYon 
{…} 
}
Item 
Processor 
@Named 
public 
class 
MyItemProcessor 
implements 
ItemProcessor 
{ 
public 
Object 
processItem(Object 
item) 
throws 
ExcepYon 
{…} 
}
Item 
Writer 
@Named 
public 
class 
MyItemWriter 
extends 
AbstractItemWriter 
{ 
public 
void 
writeItems(List<Object> 
items) 
throws 
ExcepYon 
{…} 
}
ExcepYon 
Handling 
• Job 
ExecuHon 
Fails 
on 
ExcepHon 
• Possible 
to 
Skip 
or 
Retry 
ExcepHons 
• Applied 
to 
the 
Chunk 
• Include 
or 
Exclude 
ExcepHons
ExcepYon 
Handling 
DefiniYon 
<chunk 
checkpoint-­‐policy="item” 
item-­‐count="3" 
skip-­‐limit="3" 
retry-­‐limit="3"> 
<reader 
ref="myItemReader"/> 
<processor 
ref="myItemProcessor"/> 
<writer 
ref="myItemWriter"/> 
<skippable-­‐excepYon-­‐classes> 
<include 
class="java.lang.RunYmeExcepYon"/> 
</skippable-­‐excepYon-­‐classes> 
<retryable-­‐excepYon-­‐classes> 
<exclude 
class="java.lang.IllegalArgumentExcepYon"/> 
</retryable-­‐excepYon-­‐classes> 
</chunk>
ParYYon 
• Steps 
run 
on 
mulHple 
Threads 
• One 
ParHHon 
per 
Thread 
• Define 
ParHHon 
Plan 
• CheckpoinHng 
is 
independent 
per 
Thread
ParYYon 
DefiniYon 
(In 
Step) 
<parYYon> 
<plan 
parYYons="2"> 
<properYes 
parYYon="0"> 
<property 
name="start" 
value="1"/> 
</properYes> 
<properYes 
parYYon="1"> 
<property 
name="start" 
value="11"/> 
</properYes> 
</plan> 
</parYYon>
ParYYon 
DefiniYon 
(In 
Step) 
<chunk 
item-­‐count="3"> 
<reader 
ref="myItemReader"> 
<properYes> 
<property 
name="start” 
value="#{parYYonPlan['start']}" 
/> 
</properYes> 
</reader> 
<processor 
ref="myItemProcessor"/> 
<writer 
ref="myItemWriter"/> 
</chunk>
Flow 
• Sequence 
of 
ExecuHon 
elements 
• Execute 
together 
as 
a 
unit 
• Flows, 
Steps, 
Decision 
and 
Split 
• Used 
to 
aggregate 
logical 
business.
Split 
• Concurrent 
ExecuHon 
of 
Flows 
• Each 
Flow 
run 
on 
a 
separate 
Thread 
• Is 
not 
the 
same 
as 
a 
ParHHon 
• Can 
only 
use 
Flows
Split 
and 
Flow 
DefiniYon 
<split 
id="mySplit"> 
<flow 
id="flow1"> 
<step 
id="myChunk" 
next="myBatchlet”>…</step> 
<step 
id="myBatchlet">...</step> 
</flow> 
<flow 
id="flow2"> 
<step 
id=”otherChunk" 
next=”otherBatchlet”>…</step> 
<step 
id=”otherBatchlet">...</step> 
</flow> 
</split>
ParYYon 
vs 
Split 
• ParHHon 
is 
used 
at 
the 
data 
level 
• Split 
is 
used 
at 
the 
business 
level
Decision 
• Decide 
the 
next 
TransiHon 
• Applied 
to 
Steps, 
Flows 
and 
Splits 
• It’s 
almost 
like 
an 
if 
/ 
else 
if 
• Requires 
an 
implementaHon
Decision 
DefiniYon 
<step 
id=”myStep" 
next="myDecider"> 
<batchlet 
ref="myBatchlet”/> 
</step> 
<decision 
id="myDecider" 
ref="MyDecider"> 
<next 
on="foo" 
to="myFooStep"/> 
<next 
on="bar" 
to="myBarStep"/> 
</decision>
Decision 
@Named 
public 
class 
MyDecider 
implements 
Decider 
{ 
public 
String 
decide(StepExecuYon[] 
execuYons) 
throws 
ExcepYon 
{…} 
}
TransiYons 
• TransiHon 
Elements 
define 
the 
Workflow 
• Applied 
to 
Steps, 
Flows 
and 
Decision 
• Next, 
Fail, 
End, 
Stop 
• Fail, 
End 
and 
Stop 
terminate 
a 
Job
Batch 
Exit 
Status 
• A 
Job 
and 
Steps 
has 
an 
Exit 
Status 
• Used 
to 
control 
the 
Workflow 
• STARTING, 
STARTED, 
STOPPING, 
STOPPED, 
FAILED, 
COMPLETED, 
ABANDONED
Schedule 
a 
Job 
(By 
@Schedule) 
@Singleton 
public 
class 
BatchJobRunner 
{ 
@Schedule(dayOfWeek 
= 
"Sun") 
public 
void 
scheduleJob() 
{ 
JobOperator 
jobOperator 
= 
BatchRunYme.getJobOperator(); 
jobOperator.start("myJob", 
new 
ProperYes()); 
} 
}
Schedule 
a 
Job 
(By 
ManagedScheduledExecutorService) 
@Resource(lookup="java:comp/DefaultManagedScheduledExecutorService") 
private 
ManagedScheduledExecutorService 
executor; 
public 
void 
scheduleJob() 
{ 
JobOperator 
jobOperator 
= 
BatchRunYme.getJobOperator(); 
executor.schedule( 
() 
-­‐> 
jobOperator.start("myJob", 
new 
ProperYes()), 
7, 
TimeUnit.DAYS); 
}
ImplementaYons 
• JBatch 
IBM 
(Glassfish, 
JEUS) 
• JBeret 
(Wildfly) 
• Spring 
Batch
A 
Few 
Cons 
• Lacks 
standard 
Readers 
/ 
Writers 
• No 
Generics 
• ParHHon 
only 
supports 
a 
single 
Step 
• No 
Sync 
mode
Demo 
Time
WoW 
AucYon 
House 
• World 
of 
WacraT 
is 
MMORPG 
• More 
than 
500 
servers 
in 
US 
and 
EU 
• Each 
server 
has 
2 
AucHon 
Houses 
• Trades 
around 
70k 
items 
/ 
server 
/ 
hour
WoW 
AucYon 
House 
• Data 
available 
to 
download 
• Let’s 
process 
the 
data 
• Extract 
metrics 
• Share 
the 
knowledge
Live 
Code
Resources 
• JSR-­‐352 
SpecificaHon 
hips://jcp.org/en/jsr/detail?id=352 
• Java 
EE 
Samples 
hips://github.com/javaee-­‐samples 
• Wow 
AucHon 
House 
hips://github.com/radcortez/wow-­‐aucHons
Thank 
you 
for 
A/ending! 
Roberto 
Cortez 
@radcortez 
h/p://www.radcortez.com 
Ivan 
St. 
Ivanov 
@ivan_stefanov 
h/p://nosoGskills.com
1 of 47

Recommended

Batching and Java EE (jdk.io) by
Batching and Java EE (jdk.io)Batching and Java EE (jdk.io)
Batching and Java EE (jdk.io)Ryan Cuprak
2.1K views57 slides
Working with JSON Data in PostgreSQL vs. MongoDB by
Working with JSON Data in PostgreSQL vs. MongoDBWorking with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDBScaleGrid.io
830 views46 slides
Job Queue in Golang by
Job Queue in GolangJob Queue in Golang
Job Queue in GolangBo-Yi Wu
22.3K views82 slides
Spring Batch Performance Tuning by
Spring Batch Performance TuningSpring Batch Performance Tuning
Spring Batch Performance TuningGunnar Hillert
12.3K views50 slides
Developing Microservices with Apache Camel by
Developing Microservices with Apache CamelDeveloping Microservices with Apache Camel
Developing Microservices with Apache CamelClaus Ibsen
6.8K views101 slides
Parallel batch processing with spring batch slideshare by
Parallel batch processing with spring batch   slideshareParallel batch processing with spring batch   slideshare
Parallel batch processing with spring batch slideshareMorten Andersen-Gott
15.9K views77 slides

More Related Content

What's hot

Meet Apache HBase - 2.0 by
Meet Apache HBase - 2.0Meet Apache HBase - 2.0
Meet Apache HBase - 2.0DataWorks Summit
1.1K views43 slides
Introducing the Apache Flink Kubernetes Operator by
Introducing the Apache Flink Kubernetes OperatorIntroducing the Apache Flink Kubernetes Operator
Introducing the Apache Flink Kubernetes OperatorFlink Forward
778 views37 slides
From cache to in-memory data grid. Introduction to Hazelcast. by
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.Taras Matyashovsky
42.6K views83 slides
Git and Github slides.pdf by
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdfTilton2
271 views30 slides
Version Control & Git by
Version Control & GitVersion Control & Git
Version Control & GitCraig Smith
5.2K views24 slides
Deep Dive Java 17 Devoxx UK by
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKJosé Paumard
986 views77 slides

What's hot(20)

Introducing the Apache Flink Kubernetes Operator by Flink Forward
Introducing the Apache Flink Kubernetes OperatorIntroducing the Apache Flink Kubernetes Operator
Introducing the Apache Flink Kubernetes Operator
Flink Forward778 views
From cache to in-memory data grid. Introduction to Hazelcast. by Taras Matyashovsky
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky42.6K views
Git and Github slides.pdf by Tilton2
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
Tilton2271 views
Version Control & Git by Craig Smith
Version Control & GitVersion Control & Git
Version Control & Git
Craig Smith5.2K views
Deep Dive Java 17 Devoxx UK by José Paumard
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
José Paumard986 views
Apache Ambari Stack Extensibility by Jayush Luniya
Apache Ambari Stack ExtensibilityApache Ambari Stack Extensibility
Apache Ambari Stack Extensibility
Jayush Luniya1.4K views
Autoscaling Flink with Reactive Mode by Flink Forward
Autoscaling Flink with Reactive ModeAutoscaling Flink with Reactive Mode
Autoscaling Flink with Reactive Mode
Flink Forward926 views
Integrating Apache NiFi and Apache Flink by Hortonworks
Integrating Apache NiFi and Apache FlinkIntegrating Apache NiFi and Apache Flink
Integrating Apache NiFi and Apache Flink
Hortonworks13.5K views
Apache Calcite overview by Julian Hyde
Apache Calcite overviewApache Calcite overview
Apache Calcite overview
Julian Hyde19.5K views
Rapid JCR applications development with Sling by Bertrand Delacretaz
Rapid JCR applications development with SlingRapid JCR applications development with Sling
Rapid JCR applications development with Sling
Bertrand Delacretaz15.6K views
Software architecture for high traffic website by Tung Nguyen Thanh
Software architecture for high traffic websiteSoftware architecture for high traffic website
Software architecture for high traffic website
Tung Nguyen Thanh9.2K views
Grails Connecting to MySQL by ashishkirpan
Grails Connecting to MySQLGrails Connecting to MySQL
Grails Connecting to MySQL
ashishkirpan7.8K views
Hazelcast Distributed Lock by Jadson Santos
Hazelcast Distributed LockHazelcast Distributed Lock
Hazelcast Distributed Lock
Jadson Santos3.2K views
Write microservice in golang by Bo-Yi Wu
Write microservice in golangWrite microservice in golang
Write microservice in golang
Bo-Yi Wu14.8K views
Asynchronous JavaScript Programming with Callbacks & Promises by Hùng Nguyễn Huy
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy910 views
Lessons learned from operating Data Platform on Kubernetes(EKS) by 창언 정
Lessons learned from operating Data Platform on Kubernetes(EKS)Lessons learned from operating Data Platform on Kubernetes(EKS)
Lessons learned from operating Data Platform on Kubernetes(EKS)
창언 정304 views
Collect distributed application logging using fluentd (EFK stack) by Marco Pas
Collect distributed application logging using fluentd (EFK stack)Collect distributed application logging using fluentd (EFK stack)
Collect distributed application logging using fluentd (EFK stack)
Marco Pas2.1K views

Similar to Java EE 7 Batch processing in the Real World

Spring batch by
Spring batchSpring batch
Spring batchChandan Kumar Rana
456 views25 slides
Spring Batch by
Spring BatchSpring Batch
Spring BatchJayasree Perilakkalam
247 views16 slides
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014 by
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 201450 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014Arun Gupta
2.7K views102 slides
5050 dev nation by
5050 dev nation5050 dev nation
5050 dev nationArun Gupta
2.1K views103 slides
50 features of Java EE 7 in 50 minutes at Geecon 2014 by
50 features of Java EE 7 in 50 minutes at Geecon 201450 features of Java EE 7 in 50 minutes at Geecon 2014
50 features of Java EE 7 in 50 minutes at Geecon 2014Arun Gupta
2K views102 slides
Java 7 Whats New(), Whats Next() from Oredev by
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
2.2K views84 slides

Similar to Java EE 7 Batch processing in the Real World(20)

50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014 by Arun Gupta
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 201450 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
Arun Gupta2.7K views
5050 dev nation by Arun Gupta
5050 dev nation5050 dev nation
5050 dev nation
Arun Gupta2.1K views
50 features of Java EE 7 in 50 minutes at Geecon 2014 by Arun Gupta
50 features of Java EE 7 in 50 minutes at Geecon 201450 features of Java EE 7 in 50 minutes at Geecon 2014
50 features of Java EE 7 in 50 minutes at Geecon 2014
Arun Gupta2K views
Java 7 Whats New(), Whats Next() from Oredev by Mattias Karlsson
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson2.2K views
Spring Batch Workshop by lyonjug
Spring Batch WorkshopSpring Batch Workshop
Spring Batch Workshop
lyonjug6.3K views
Javazone 2019 - Mutants to the rescue: How effective are your unit tests? by Paco van Beckhoven
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?Javazone 2019 - Mutants to the rescue: How effective are your unit tests?
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?
Paco van Beckhoven142 views
50 New Features of Java EE 7 in 50 minutes by Arun Gupta
50 New Features of Java EE 7 in 50 minutes50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutes
Arun Gupta4.9K views
vJUG - The JavaFX Ecosystem by Andres Almiray
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX Ecosystem
Andres Almiray3.6K views
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013 by Arun Gupta
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Arun Gupta6.7K views
Code transformation With Spoon by Gérard Paligot
Code transformation With SpoonCode transformation With Spoon
Code transformation With Spoon
Gérard Paligot1.7K views
Javatwo2012 java frameworkcomparison by Jini Lee
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparison
Jini Lee896 views
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate by Thorben Janssen
Effiziente Datenpersistierung mit JPA 2.1 und HibernateEffiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Thorben Janssen3.5K views
Spring batch showCase by taher abdo
Spring batch showCaseSpring batch showCase
Spring batch showCase
taher abdo99 views

More from Roberto Cortez

Chasing the RESTful Trinity - Client CLI and Documentation by
Chasing the RESTful Trinity - Client CLI and DocumentationChasing the RESTful Trinity - Client CLI and Documentation
Chasing the RESTful Trinity - Client CLI and DocumentationRoberto Cortez
740 views35 slides
Baking a Microservice PI(e) by
Baking a Microservice PI(e)Baking a Microservice PI(e)
Baking a Microservice PI(e)Roberto Cortez
478 views188 slides
GraalVM and MicroProfile - A Polyglot Microservices Solution by
GraalVM and MicroProfile - A Polyglot Microservices SolutionGraalVM and MicroProfile - A Polyglot Microservices Solution
GraalVM and MicroProfile - A Polyglot Microservices SolutionRoberto Cortez
986 views45 slides
Deconstructing and Evolving REST Security by
Deconstructing and Evolving REST SecurityDeconstructing and Evolving REST Security
Deconstructing and Evolving REST SecurityRoberto Cortez
193 views113 slides
Lightweight Enterprise Java With Microprofile by
Lightweight Enterprise Java With MicroprofileLightweight Enterprise Java With Microprofile
Lightweight Enterprise Java With MicroprofileRoberto Cortez
1.3K views60 slides
Cluster your MicroProfile Application using CDI and JCache by
Cluster your MicroProfile Application using CDI and JCacheCluster your MicroProfile Application using CDI and JCache
Cluster your MicroProfile Application using CDI and JCacheRoberto Cortez
972 views35 slides

More from Roberto Cortez(15)

Chasing the RESTful Trinity - Client CLI and Documentation by Roberto Cortez
Chasing the RESTful Trinity - Client CLI and DocumentationChasing the RESTful Trinity - Client CLI and Documentation
Chasing the RESTful Trinity - Client CLI and Documentation
Roberto Cortez740 views
GraalVM and MicroProfile - A Polyglot Microservices Solution by Roberto Cortez
GraalVM and MicroProfile - A Polyglot Microservices SolutionGraalVM and MicroProfile - A Polyglot Microservices Solution
GraalVM and MicroProfile - A Polyglot Microservices Solution
Roberto Cortez986 views
Deconstructing and Evolving REST Security by Roberto Cortez
Deconstructing and Evolving REST SecurityDeconstructing and Evolving REST Security
Deconstructing and Evolving REST Security
Roberto Cortez193 views
Lightweight Enterprise Java With Microprofile by Roberto Cortez
Lightweight Enterprise Java With MicroprofileLightweight Enterprise Java With Microprofile
Lightweight Enterprise Java With Microprofile
Roberto Cortez1.3K views
Cluster your MicroProfile Application using CDI and JCache by Roberto Cortez
Cluster your MicroProfile Application using CDI and JCacheCluster your MicroProfile Application using CDI and JCache
Cluster your MicroProfile Application using CDI and JCache
Roberto Cortez972 views
The First Contact with Java EE 7 by Roberto Cortez
The First Contact with Java EE 7The First Contact with Java EE 7
The First Contact with Java EE 7
Roberto Cortez600 views
Migration tales from java ee 5 to 7 by Roberto Cortez
Migration tales from java ee 5 to 7Migration tales from java ee 5 to 7
Migration tales from java ee 5 to 7
Roberto Cortez15.3K views
Development Horror Stories by Roberto Cortez
Development Horror StoriesDevelopment Horror Stories
Development Horror Stories
Roberto Cortez8.5K views
The 5 People in your Organization that grow Legacy Code by Roberto Cortez
The 5 People in your Organization that grow Legacy CodeThe 5 People in your Organization that grow Legacy Code
The 5 People in your Organization that grow Legacy Code
Roberto Cortez8.4K views
Geecon 2014 - Five Ways to Not Suck at Being a Java Freelancer by Roberto Cortez
Geecon 2014 - Five Ways to Not Suck at Being a Java FreelancerGeecon 2014 - Five Ways to Not Suck at Being a Java Freelancer
Geecon 2014 - Five Ways to Not Suck at Being a Java Freelancer
Roberto Cortez7.4K views
Coimbra JUG - 2º Encontro - O primeiro contacto com Java EE 7 by Roberto Cortez
Coimbra JUG - 2º Encontro - O primeiro contacto com Java EE 7Coimbra JUG - 2º Encontro - O primeiro contacto com Java EE 7
Coimbra JUG - 2º Encontro - O primeiro contacto com Java EE 7
Roberto Cortez3.1K views
Coimbra JUG - 1º Encontro - As novidades do Java 8 by Roberto Cortez
Coimbra JUG - 1º Encontro - As novidades do Java 8Coimbra JUG - 1º Encontro - As novidades do Java 8
Coimbra JUG - 1º Encontro - As novidades do Java 8
Roberto Cortez878 views

Recently uploaded

Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... by
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...The Digital Insurer
86 views52 slides
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...ShapeBlue
117 views25 slides
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue by
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueShapeBlue
163 views54 slides
Generative AI: Shifting the AI Landscape by
Generative AI: Shifting the AI LandscapeGenerative AI: Shifting the AI Landscape
Generative AI: Shifting the AI LandscapeDeakin University
43 views55 slides
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...Bernd Ruecker
50 views69 slides
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueShapeBlue
93 views15 slides

Recently uploaded(20)

Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... by The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue117 views
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue by ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
ShapeBlue163 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue93 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc160 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash153 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue179 views
Business Analyst Series 2023 - Week 4 Session 8 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 8Business Analyst Series 2023 -  Week 4 Session 8
Business Analyst Series 2023 - Week 4 Session 8
DianaGray1086 views
State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue253 views
Initiating and Advancing Your Strategic GIS Governance Strategy by Safe Software
Initiating and Advancing Your Strategic GIS Governance StrategyInitiating and Advancing Your Strategic GIS Governance Strategy
Initiating and Advancing Your Strategic GIS Governance Strategy
Safe Software140 views
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... by ShapeBlue
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
ShapeBlue79 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays53 views
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue94 views
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ by ShapeBlue
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
ShapeBlue88 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE69 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue166 views

Java EE 7 Batch processing in the Real World

  • 1. Java EE 7 Batch Processing in the Real World Roberto Cortez & Ivan St. Ivanov JavaOne 2014 #CON2818
  • 2. Who are we? Roberto Cortez @radcortez h/p://www.radcortez.com Freelancer, Speaker, RebelLabs Author, Blogger Ivan St. Ivanov @ivan_stefanov h/p://nosoGskills.com Architect, SAP Labs Bulgaria, JBoss Forge contributor
  • 3. QuesHons? As soon as you have them!
  • 4. What is Batch? “A group of records processed as a single unit, usually without input from a user.” (from Google)
  • 5. Why Batch? (Computers) • Make use of idle resources • ShiT the Hme of processing • Manage large repeated work easily • Shared by mulHple users
  • 6. Batch is in our lives • By paying bills • On the grocery • In traffic • Cooking food
  • 7. Why Batch? (General) • Efficiency • Focus on a single problem • Avoid context switch • Reduce costs
  • 8. State of the Art • Spring Batch • IBM Websphere • Hadoop • Java SE, Scheduler, in-­‐house frameworks
  • 9. The JSR-­‐352 • Batch ApplicaHons for the Java pla]orm • Heavily inspired by Spring Batch • Available since Java EE 7 • Also designed for Java SE
  • 10. The JSR-­‐352 Features • Task and Chunk oriented processing • SequenHal and/or Parallel execuHon • CheckpoinHng • Workflow • Stop and restart • ExcepHon handling
  • 11. Batch Domain Language Job Operator Job Step Job Repository Item Reader Item Processor Item Writer 1 *
  • 12. Job composiYon * Job Step * JobInstance * * * JobExecuYon StepExecuYon
  • 14. Batchlet DefiniYon @Named public class MyBatchlet extends AbstractBatchlet { @Override public String process() { System.out.println("Running inside a batchlet"); return BatchStatus.COMPLETED.toString(); } }
  • 15. Job SpecificaYon Language <job id="myFirstBatch"> <step id="myStep" > <batchlet ref="myBatchlet"/> </step> </job>
  • 16. Start the Job JobOperator jobOperator = BatchRunYme.getJobOperator(); Long execuYonId = jobOperator.start("myJob", new ProperYes()); JobExecuYon jobExecuYon = jobOperator.getJobExecuYon(execuYonId);
  • 17. Batchlet • Task oriented Batch Step • Suitable for • Short execuHons • Handle system resources • IniHalizaHon and Cleanup
  • 18. Chunk • ETL style (Reader, Processor, Writer) • Suitable for • Handle large amounts of data • Failover safety (checkpoint) • Long running applicaHons
  • 19. Chunk Processing Step ItemReader ItemProcessor ItemWriter read() read() process(item) process(item) write(items) item item item item execute() ExitStatus
  • 20. Defining Chunk Step <step id="myChunk"> <chunk checkpoint-­‐policy="item" item-­‐count="3"> <reader ref=“myItemReader"/> <processor ref=“myItemProcessor"/> <writer ref=“myItemWriter"/> </chunk> </step>
  • 21. Item Reader @Named public class MyItemReader extends AbstractItemReader { public Object readItem() throws ExcepYon {…} }
  • 22. Item Processor @Named public class MyItemProcessor implements ItemProcessor { public Object processItem(Object item) throws ExcepYon {…} }
  • 23. Item Writer @Named public class MyItemWriter extends AbstractItemWriter { public void writeItems(List<Object> items) throws ExcepYon {…} }
  • 24. ExcepYon Handling • Job ExecuHon Fails on ExcepHon • Possible to Skip or Retry ExcepHons • Applied to the Chunk • Include or Exclude ExcepHons
  • 25. ExcepYon Handling DefiniYon <chunk checkpoint-­‐policy="item” item-­‐count="3" skip-­‐limit="3" retry-­‐limit="3"> <reader ref="myItemReader"/> <processor ref="myItemProcessor"/> <writer ref="myItemWriter"/> <skippable-­‐excepYon-­‐classes> <include class="java.lang.RunYmeExcepYon"/> </skippable-­‐excepYon-­‐classes> <retryable-­‐excepYon-­‐classes> <exclude class="java.lang.IllegalArgumentExcepYon"/> </retryable-­‐excepYon-­‐classes> </chunk>
  • 26. ParYYon • Steps run on mulHple Threads • One ParHHon per Thread • Define ParHHon Plan • CheckpoinHng is independent per Thread
  • 27. ParYYon DefiniYon (In Step) <parYYon> <plan parYYons="2"> <properYes parYYon="0"> <property name="start" value="1"/> </properYes> <properYes parYYon="1"> <property name="start" value="11"/> </properYes> </plan> </parYYon>
  • 28. ParYYon DefiniYon (In Step) <chunk item-­‐count="3"> <reader ref="myItemReader"> <properYes> <property name="start” value="#{parYYonPlan['start']}" /> </properYes> </reader> <processor ref="myItemProcessor"/> <writer ref="myItemWriter"/> </chunk>
  • 29. Flow • Sequence of ExecuHon elements • Execute together as a unit • Flows, Steps, Decision and Split • Used to aggregate logical business.
  • 30. Split • Concurrent ExecuHon of Flows • Each Flow run on a separate Thread • Is not the same as a ParHHon • Can only use Flows
  • 31. Split and Flow DefiniYon <split id="mySplit"> <flow id="flow1"> <step id="myChunk" next="myBatchlet”>…</step> <step id="myBatchlet">...</step> </flow> <flow id="flow2"> <step id=”otherChunk" next=”otherBatchlet”>…</step> <step id=”otherBatchlet">...</step> </flow> </split>
  • 32. ParYYon vs Split • ParHHon is used at the data level • Split is used at the business level
  • 33. Decision • Decide the next TransiHon • Applied to Steps, Flows and Splits • It’s almost like an if / else if • Requires an implementaHon
  • 34. Decision DefiniYon <step id=”myStep" next="myDecider"> <batchlet ref="myBatchlet”/> </step> <decision id="myDecider" ref="MyDecider"> <next on="foo" to="myFooStep"/> <next on="bar" to="myBarStep"/> </decision>
  • 35. Decision @Named public class MyDecider implements Decider { public String decide(StepExecuYon[] execuYons) throws ExcepYon {…} }
  • 36. TransiYons • TransiHon Elements define the Workflow • Applied to Steps, Flows and Decision • Next, Fail, End, Stop • Fail, End and Stop terminate a Job
  • 37. Batch Exit Status • A Job and Steps has an Exit Status • Used to control the Workflow • STARTING, STARTED, STOPPING, STOPPED, FAILED, COMPLETED, ABANDONED
  • 38. Schedule a Job (By @Schedule) @Singleton public class BatchJobRunner { @Schedule(dayOfWeek = "Sun") public void scheduleJob() { JobOperator jobOperator = BatchRunYme.getJobOperator(); jobOperator.start("myJob", new ProperYes()); } }
  • 39. Schedule a Job (By ManagedScheduledExecutorService) @Resource(lookup="java:comp/DefaultManagedScheduledExecutorService") private ManagedScheduledExecutorService executor; public void scheduleJob() { JobOperator jobOperator = BatchRunYme.getJobOperator(); executor.schedule( () -­‐> jobOperator.start("myJob", new ProperYes()), 7, TimeUnit.DAYS); }
  • 40. ImplementaYons • JBatch IBM (Glassfish, JEUS) • JBeret (Wildfly) • Spring Batch
  • 41. A Few Cons • Lacks standard Readers / Writers • No Generics • ParHHon only supports a single Step • No Sync mode
  • 43. WoW AucYon House • World of WacraT is MMORPG • More than 500 servers in US and EU • Each server has 2 AucHon Houses • Trades around 70k items / server / hour
  • 44. WoW AucYon House • Data available to download • Let’s process the data • Extract metrics • Share the knowledge
  • 46. Resources • JSR-­‐352 SpecificaHon hips://jcp.org/en/jsr/detail?id=352 • Java EE Samples hips://github.com/javaee-­‐samples • Wow AucHon House hips://github.com/radcortez/wow-­‐aucHons
  • 47. Thank you for A/ending! Roberto Cortez @radcortez h/p://www.radcortez.com Ivan St. Ivanov @ivan_stefanov h/p://nosoGskills.com