complex business rules processed repetitively across very large data sets, or integration of information that..requires formatting, validation, and processing in a transactional manner" (Spring Source)
process Consists of at least 1 Step STEP Encapsulates a single (simple or complex) task within the batch process Has exactly 1 ItemReader & 1 ItemWriter Optionally has 1 ItemProcessor
data to configure/execute the job JobInstance The execution of a Job for given set of JobParameters JobInstance = Job + JobParameters JobExecution A single attempt at executing a JobInstance Many executions for a single instance Instance is complete when an execution completes StepExecution A single attempt at executing a Step within a Job. [ h t t p : / / w w w . s l i d e s h a r e . n e t / g s c h m u t z / s p r i n g - b a t c h - 2 0 - 2 7 9 4 0 1 5 ]
p s : / / r a w . g i t h u b . c o m / S p r i n g S o u r c e / s p r i n g - b a t c h / m a s t e r / s r c / s i t e / d o c b o o k / r e f e r e n c e / i m a g e s / j o b H e i r a r c h y W i t h S t e p s . p n g ]
input data for a step Retrieves 1 item at a time Returns null when input is exhausted < f o n t s t y l e = " f o n t - s i z e : 2 4 p x ; " > p a c k a g e o r g . s p r i n g f r a m e w o r k . b a t c h . i t e m ; p u b l i c i n t e r f a c e I t e m R e a d e r < T > { T r e a d ( ) t h r o w s E x c e p t i o n , U n e x p e c t e d I n p u t E x c e p t i o n , P a r s e E x c e p t i o n , N o n T r a n s i e n t R e s o } < / f o n t >
input item to output item Processes 1 item at a time Returns null to indicate that result should not be saved < f o n t s t y l e = " f o n t - s i z e : 2 4 p x ; " > p a c k a g e o r g . s p r i n g f r a m e w o r k . b a t c h . i t e m ; p u b l i c i n t e r f a c e I t e m P r o c e s s o r < I , O > { O p r o c e s s ( I i ) t h r o w s E x c e p t i o n ; } < / f o n t >
of Step Chunk-Oriented Transaction is committed for a series of ItemWriter calls Receives a List of read or processed items List size is size of commit-interval < f o n t s t y l e = " f o n t - s i z e : 2 4 p x ; " > p a c k a g e o r g . s p r i n g f r a m e w o r k . b a t c h . i t e m ; p u b l i c i n t e r f a c e I t e m W r i t e r < T > { v o i d w r i t e ( L i s t < ? e x t e n d s T > i t e m s ) t h r o w s E x c e p t i o n ; } < / f o n t >
p s : / / r a w . g i t h u b . c o m / S p r i n g S o u r c e / s p r i n g - b a t c h / m a s t e r / s r c / s i t e / d o c b o o k / r e f e r e n c e / i m a g e s / c h u n k - o r i e n t e d - p r o c e s s i n g . p n g ]
- May 24, 2013 Designed for both Java SE and Java EE platforms Requires Java 6+ Designed with DI in mind without specifying a DI implementation Based on the Chunk-Oriented Processing and Reader- Processor-Writer patterns of Spring Batch [ h t t p : / / j c p . o r g / a b o u t J a v a / c o m m u n i t y p r o c e s s / f i n a l / j s r 3 5 2 / i n d e x . h t m l ]
JSR-352 requires Job XML documents in META-INF/batch- jobs JSR-352 item count or time based commit-intervals JSR-352 batchlet and chunk are mutually exclusive, Spring Batch chunk is encapsulated by tasklet [ h t t p : / / w w w . i n f o q . c o m / n e w s / 2 0 1 3 / 0 6 / e e 7 - s p r i n g - b a t c h ]
detection of batch configuration files (grails- app/batch) Automatic configuration reloading during development JMX integration Automatic deployment of Spring Batch DDL Specify the database type UI Services for providing access to Spring Batch data Base views that mimic Spring Batch Admin views
application. Modify configuration in Config.groovy p l u g i n { s p r i n g B a t c h { d a t a b a s e = ' m y s q l ' l o a d T a b l e s = f a l s e } } < b r > e n v i r o n m e n t s { t e s t { p l u g i n . s p r i n g B a t c h . d a t a b a s e = ' h 2 ' p l u g i n . s p r i n g B a t c h . l o a d T a b l e s = t r u e < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > } < / s p a n > < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > } < / s p a n >
application Be aware of cross datasource transactions when using this mode. No XA management by default in Grails Specify a prefix for Spring Batch tables All spring batch tables are in UPPERCASE. Be aware for case sensitive DBs & File Systems p l u g i n . s p r i n g B a t c h . d a t a S o u r c e = ' b a t c h D a t a S o u r c e ' p l u g i n . s p r i n g B a t c h . t a b l e P r e f i x = ' S P R I N G B A T C H _ '
BatchConfig.groovy Wrap definition with a 'beans' closure g r a i l s - a p p / b a t c h / S i m p l e J o b B a t c h C o n f i g . g r o o v y < f o n t c o l o r = " # f f 0 0 0 0 " > b e a n s < / f o n t > { }
BatchConfig.groovy Wrap definition with a 'beans' closure Define jobs using the 'batch' prefix g r a i l s - a p p / b a t c h / S i m p l e J o b B a t c h C o n f i g . g r o o v y < f o n t c o l o r = " # f f 0 0 0 0 " > b e a n s < / f o n t > { } b e a n s { < f o n t c o l o r = " # f f 0 0 0 0 " > b a t c h . j o b < / f o n t > ( i d : ' s i m p l e J o b ' ) { < f o n t c o l o r = " # f f 0 0 0 0 " > b a t c h . s t e p < / f o n t > ( i d : ' l o g S t a r t ' ) { < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > . . . < / s p a n > < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > } < / s p a n > < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > } < / s p a n > < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > } < / s p a n >
Job components b e a n s { b a t c h . j o b ( i d : ' s i m p l e J o b ' ) b a t c h . s t e p ( i d : ' l o g S t a r t ' ) { b a t c h . t a s k l e t ( r e f : ' l o g S t a r t ' ) } } < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > < b r > < / s p a n > < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > l o g S t a r t ( P r i n t S t a r t M e s s a g e T a s k l e t ) { b e a n - > < / s p a < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > b e a n . a u t o w i r e = ' b y N a m e ' < / s p a n > < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > } < / s p a n > < s p a n s t y l e = " f o n t - f a m i l y : m o n o s p a c e ; " > } < / s p a n >
Each Job is also registered as a Spring bean Use Grails DI to access and call < s p a n > c l a s s S i m p l e J o b S e r v i c e { < / s p a n > < b r > J o b L a u n c h e r j o b L a u n c h e r / / r e g i s t e r e d b y p l u g i n }
Each Job is also registered as a Spring bean Use Grails DI to access and call < s p a n > c l a s s S i m p l e J o b S e r v i c e { < / s p a n > < b r > J o b L a u n c h e r j o b L a u n c h e r / / r e g i s t e r e d b y p l u g i n J o b s i m p l e J o b / / r e g i s t e r e d b y d e f i n i n g t h e J o b }
Each Job is also registered as a Spring bean Use Grails DI to access and call < s p a n > c l a s s S i m p l e J o b S e r v i c e { < / s p a n > < b r > J o b L a u n c h e r j o b L a u n c h e r / / r e g i s t e r e d b y p l u g i n J o b s i m p l e J o b / / r e g i s t e r e d b y d e f i n i n g t h e J o b < b r > L o n g e x e c u t e ( ) { } }
Each Job is also registered as a Spring bean Use Grails DI to access and call < s p a n > c l a s s S i m p l e J o b S e r v i c e { < / s p a n > < b r > J o b L a u n c h e r j o b L a u n c h e r / / r e g i s t e r e d b y p l u g i n J o b s i m p l e J o b / / r e g i s t e r e d b y d e f i n i n g t h e J o b < b r > L o n g e x e c u t e ( ) { J o b P a r a m e t e r s B u i l d e r b u i l d e r = n e w J o b P a r a m e t e r s B u i l d e r ( ) b u i l d e r . a d d S t r i n g ( ' b a s e M e s s a g e ' , ' s o m e b a s e t e x t ' ) } }
Each Job is also registered as a Spring bean Use Grails DI to access and call < s p a n > c l a s s S i m p l e J o b S e r v i c e { < / s p a n > < b r > J o b L a u n c h e r j o b L a u n c h e r / / r e g i s t e r e d b y p l u g i n J o b s i m p l e J o b / / r e g i s t e r e d b y d e f i n i n g t h e J o b < b r > L o n g e x e c u t e ( ) { J o b P a r a m e t e r s B u i l d e r b u i l d e r = n e w J o b P a r a m e t e r s B u i l d e r ( ) b u i l d e r . a d d S t r i n g ( ' b a s e M e s s a g e ' , ' s o m e b a s e t e x t ' ) < b r > J o b E x e c u t i o n j o b E x e c u t i o n = j o b L a u n c h e r . r u n ( s i m p l e J o b , b u i l d e r . t o J o b P a r a m e t e r s ( ) r e t u r n j o b E x e c u t i o n . j o b I d } }
p r i n g B a t c h F o o t b a l l h t t p s : / / g i t h u b . c o m / j o h n r e n g e l m a n / g r a i l s - s p r i n g - b a t c h - e x a m p l e h t t p s : / / g i t h u b . c o m / s p r i n g - p r o j e c t s / s p r i n g - b a t c h / b l o b / m a s t e r / s p r i n g - b a t c h - s a m p l e s / s r c / m a i n / r e s o u r c e s / j o b s / f o o t b a l l J o b . x m l