SlideShare une entreprise Scribd logo
1  sur  47
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Dongwon Kim – A Comparative Performance Evaluation of Flink
Dongwon Kim – A Comparative Performance Evaluation of FlinkDongwon Kim – A Comparative Performance Evaluation of Flink
Dongwon Kim – A Comparative Performance Evaluation of Flink
Flink Forward
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Dvir Volk
 

Tendances (20)

Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Functional Application Logging : Code Examples Using Spring Boot and Logback
Functional Application Logging : Code Examples Using Spring Boot and LogbackFunctional Application Logging : Code Examples Using Spring Boot and Logback
Functional Application Logging : Code Examples Using Spring Boot and Logback
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
 
Introduce yourself to java 17
Introduce yourself to java 17Introduce yourself to java 17
Introduce yourself to java 17
 
Getting Started with Apache Spark on Kubernetes
Getting Started with Apache Spark on KubernetesGetting Started with Apache Spark on Kubernetes
Getting Started with Apache Spark on Kubernetes
 
Data race
Data raceData race
Data race
 
Apache Kafka
Apache KafkaApache Kafka
Apache Kafka
 
Dongwon Kim – A Comparative Performance Evaluation of Flink
Dongwon Kim – A Comparative Performance Evaluation of FlinkDongwon Kim – A Comparative Performance Evaluation of Flink
Dongwon Kim – A Comparative Performance Evaluation of Flink
 
Distributed stream processing with Apache Kafka
Distributed stream processing with Apache KafkaDistributed stream processing with Apache Kafka
Distributed stream processing with Apache Kafka
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Netflix viewing data architecture evolution - QCon 2014
Netflix viewing data architecture evolution - QCon 2014Netflix viewing data architecture evolution - QCon 2014
Netflix viewing data architecture evolution - QCon 2014
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
 
카프카, 산전수전 노하우
카프카, 산전수전 노하우카프카, 산전수전 노하우
카프카, 산전수전 노하우
 
How to improve ELK log pipeline performance
How to improve ELK log pipeline performanceHow to improve ELK log pipeline performance
How to improve ELK log pipeline performance
 
Introduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlIntroduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission Control
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaProducer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache Kafka
 
Postman. From simple API test to end to end scenario
Postman. From simple API test to end to end scenarioPostman. From simple API test to end to end scenario
Postman. From simple API test to end to end scenario
 
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
 
Client side attacks using PowerShell
Client side attacks using PowerShellClient side attacks using PowerShell
Client side attacks using PowerShell
 
Writing Clean Code in Swift
Writing Clean Code in SwiftWriting Clean Code in Swift
Writing Clean Code in Swift
 

Similaire à Java EE 7 Batch processing in the Real World

5050 dev nation
5050 dev nation5050 dev nation
5050 dev nation
Arun Gupta
 

Similaire à Java EE 7 Batch processing in the Real World (20)

Spring batch
Spring batchSpring batch
Spring batch
 
Spring Batch
Spring BatchSpring Batch
Spring Batch
 
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
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
 
5050 dev nation
5050 dev nation5050 dev nation
5050 dev nation
 
50 features of Java EE 7 in 50 minutes at Geecon 2014
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
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Spring Batch Workshop
Spring Batch WorkshopSpring Batch Workshop
Spring Batch Workshop
 
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?
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?
 
50 New Features of Java EE 7 in 50 minutes
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
 
Effiziente persistierung
Effiziente persistierungEffiziente persistierung
Effiziente persistierung
 
Java Batch
Java BatchJava Batch
Java Batch
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX Ecosystem
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
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
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Code transformation With Spoon
Code transformation With SpoonCode transformation With Spoon
Code transformation With Spoon
 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparison
 
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und HibernateEffiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
 
Struts2 - 101
Struts2 - 101Struts2 - 101
Struts2 - 101
 
Spring batch showCase
Spring batch showCaseSpring batch showCase
Spring batch showCase
 

Plus de Roberto Cortez

Coimbra JUG - 2º Encontro - O primeiro contacto com Java EE 7
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 Cortez
 
Coimbra JUG - 1º Encontro - As novidades do Java 8
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 Cortez
 

Plus de Roberto Cortez (15)

Chasing the RESTful Trinity - Client CLI and Documentation
Chasing the RESTful Trinity - Client CLI and DocumentationChasing the RESTful Trinity - Client CLI and Documentation
Chasing the RESTful Trinity - Client CLI and Documentation
 
Baking a Microservice PI(e)
Baking a Microservice PI(e)Baking a Microservice PI(e)
Baking a Microservice PI(e)
 
GraalVM and MicroProfile - A Polyglot Microservices Solution
GraalVM and MicroProfile - A Polyglot Microservices SolutionGraalVM and MicroProfile - A Polyglot Microservices Solution
GraalVM and MicroProfile - A Polyglot Microservices Solution
 
Deconstructing and Evolving REST Security
Deconstructing and Evolving REST SecurityDeconstructing and Evolving REST Security
Deconstructing and Evolving REST Security
 
Lightweight Enterprise Java With Microprofile
Lightweight Enterprise Java With MicroprofileLightweight Enterprise Java With Microprofile
Lightweight Enterprise Java With Microprofile
 
Cluster your MicroProfile Application using CDI and JCache
Cluster your MicroProfile Application using CDI and JCacheCluster your MicroProfile Application using CDI and JCache
Cluster your MicroProfile Application using CDI and JCache
 
Java EE 7 meets Java 8
Java EE 7 meets Java 8Java EE 7 meets Java 8
Java EE 7 meets Java 8
 
Maven - Taming the Beast
Maven - Taming the BeastMaven - Taming the Beast
Maven - Taming the Beast
 
The First Contact with Java EE 7
The First Contact with Java EE 7The First Contact with Java EE 7
The First Contact with Java EE 7
 
Migration tales from java ee 5 to 7
Migration tales from java ee 5 to 7Migration tales from java ee 5 to 7
Migration tales from java ee 5 to 7
 
Development Horror Stories
Development Horror StoriesDevelopment Horror Stories
Development Horror Stories
 
The 5 People in your Organization that grow Legacy Code
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
 
Geecon 2014 - Five Ways to Not Suck at Being a Java Freelancer
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
 
Coimbra JUG - 2º Encontro - O primeiro contacto com Java EE 7
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
 
Coimbra JUG - 1º Encontro - As novidades do Java 8
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
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

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