This repository was archived by the owner on Jan 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathbatch-processing005.html
More file actions
583 lines (569 loc) · 23.7 KB
/
batch-processing005.html
File metadata and controls
583 lines (569 loc) · 23.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Creating Batch Artifacts</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/style.css" rel="stylesheet">
<script src="https://use.fontawesome.com/96c4d89611.js"></script>
</head>
<body>
<table id="doc-title" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top">
<b>Java Platform, Enterprise Edition (Java EE) 8</b><br />
<b>The Java EE Tutorial</b>
<!-- <p class="beta">Beta Draft (Pre-General Availability)</p> -->
</td>
</tr>
</table>
<hr />
<table width="90%" id="top-nav" cellspacing="0" cellpadding="0">
<colgroup>
<col width="12%"/>
<col width="12%"/>
<col width="*"/>
</colgroup>
<tr>
<td align="left">
<a href="batch-processing004.html">
<span class="vector-font"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Previous</span>
</a>
</td>
<td align="left">
<a href="batch-processing006.html">
<span class=" vector-font"><i class="fa fa-arrow-circle-right vector-font" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Next</span>
</a>
</td>
<td align="right">
<a href="toc.html">
<span class=" vector-font"><i class="fa fa-list vector-font" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Contents</span>
</a>
</td>
</tr>
</table>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p><a id="BCGHDHGH"></a><a id="creating-batch-artifacts"></a></p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_creating_batch_artifacts">Creating Batch Artifacts</h2>
<div class="sectionbody">
<div class="paragraph">
<p>After you define a job in terms of its batch artifacts using the Job
Specification Language (JSL), you create these artifacts as Java classes
that implement the interfaces in the <code>javax.batch.api</code> package and its
subpackages.</p>
</div>
<div class="paragraph">
<p>This section lists the main batch artifact interfaces, demonstrates how
to access context objects from the batch runtime, and provides some
examples.</p>
</div>
<div class="paragraph">
<p>The following topics are addressed here:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#BABDAIBI">Batch Artifact Interfaces</a></p>
</li>
<li>
<p><a href="#BCGIFJBB">Dependency Injection in Batch Artifacts</a></p>
</li>
<li>
<p><a href="#BCGCJEEF">Using the Context Objects from the Batch Runtime</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p><a id="BABDAIBI"></a><a id="batch-artifact-interfaces"></a></p>
</div>
<div class="sect2">
<h3 id="_batch_artifact_interfaces">Batch Artifact Interfaces</h3>
<div class="paragraph">
<p>The following tables list the interfaces that you implement to create
batch artifacts. The interface implementations are referenced from the
elements described in <a href="batch-processing004.html#BCGDDBBG">Using the
Job Specification Language</a>.</p>
</div>
<div class="paragraph">
<p><a href="#BCGGCIDC">Table 58-3</a> lists the interfaces to implement batch
artifacts for chunk steps, task steps, and decision elements.</p>
</div>
<div class="paragraph">
<p><a href="#BCGEAAEA">Table 58-4</a> lists the interfaces to implement batch
artifacts for partitioned steps.</p>
</div>
<div class="paragraph">
<p><a href="#BCGCAEDI">Table 58-5</a> lists the interfaces to implement batch
artifacts for job and step listeners.</p>
</div>
<div class="paragraph">
<p><a id="sthref279"></a><a id="BCGGCIDC"></a></p>
</div>
<div class="paragraph">
<p><strong>Table 58-3 Main Batch Artifact Interfaces</strong></p>
</div>
<table class="tableblock frame-all grid-all" style="width: 99%;">
<colgroup>
<col style="width: 15%;">
<col style="width: 15%;">
<col style="width: 70%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Package</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Interface</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Description</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Batchlet</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Implements the business logic of a
task-oriented step. It is referenced from the <code>batchlet</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Decider</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Decides the next step, flow, or split to
execute based on information from the execution of the previous step,
flow, or split. It is referenced from the <code>decision</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>CheckPointAlgorithm</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Implements a custom
checkpoint policy for chunk steps. It is referenced from the
<code>checkpoint-algorithm</code> element inside the <code>chunk</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ItemReader</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Reads items from an input source
in a chunk step. It is referenced from the <code>reader</code> element inside the
<code>chunk</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ItemProcessor</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Processes input items to
obtain output items in chunk steps. It is referenced from the
<code>processor</code> element inside the <code>chunk</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ItemWriter</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Writes output items in chunk
steps. It is referenced from the <code>writer</code> element inside the <code>chunk</code>
element.</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><a id="sthref280"></a><a id="BCGEAAEA"></a></p>
</div>
<div class="paragraph">
<p>Table 58-4 Partition Batch Artifact Interfaces</p>
</div>
<table class="tableblock frame-all grid-all" style="width: 99%;">
<colgroup>
<col style="width: 15%;">
<col style="width: 15%;">
<col style="width: 70%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Package</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Interface</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Description</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.partition</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PartitionPlan</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Provides details on how
to execute a partitioned step, such as the number of partitions, the
number of threads, and the parameters for each partition. This artifact
is not referenced directly from the job definition file.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.partition</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PartitionMapper</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Provides a
<code>PartitionPlan</code> object. It is referenced from the <code>mapper</code> element
inside the <code>partition</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.partition</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PartitionReducer</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Receives control when
a partitioned step begins, ends, or rolls back. It is referenced from
the <code>reducer</code> element inside the <code>partition</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.partition</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PartitionCollector</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Sends intermediary
results from each partition to a partition analyzer. It is referenced
from the <code>collector</code> element inside the <code>partition</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.partition</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PartitionAnalyzer</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Processes data and
final results from each partition. It is referenced from the <code>analyzer</code>
element inside the <code>partition</code> element.</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><a id="sthref281"></a><a id="BCGCAEDI"></a></p>
</div>
<div class="paragraph">
<p><strong>Table 58-5 Listener Batch Artifact Interfaces</strong></p>
</div>
<table class="tableblock frame-all grid-all" style="width: 99%;">
<colgroup>
<col style="width: 15%;">
<col style="width: 15%;">
<col style="width: 70%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Package</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Interface</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Description</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>JobListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts job execution
before and after running a job. It is referenced from the <code>listener</code>
element inside the <code>job</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>StepListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts step execution
before and after running a step. It is referenced from the <code>listener</code>
element inside the <code>step</code> element</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ChunkListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts chunk
processing in chunk steps before and after processing each chunk, and on
errors. It is referenced from the <code>listener</code> element inside the <code>step</code>
element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ItemReadListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts item
reading in chunk steps before and after reading each item, and on
errors. It is referenced from the <code>listener</code> element inside the <code>step</code>
element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ItemProcessListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts
item processing in chunk steps before and after processing each item,
and on errors. It is referenced from the <code>listener</code> element inside the
<code>step</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ItemWriteListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts item
writing in chunk steps before and after writing each item, and on
errors. It is referenced from the <code>listener</code> element inside the <code>step</code>
element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>RetryReadListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts retry
item reading in chunk steps when an exception occurs. It is referenced
from the <code>listener</code> element inside the <code>step</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>RetryProcessListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts
retry item processing in chunk steps when an exception occurs. It is
referenced from the <code>listener</code> element inside the <code>step</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>RetryWriteListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts
retry item writing in chunk steps when an exception occurs. It is
referenced from the <code>listener</code> element inside the <code>step</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>SkipReadListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts
skippable exception handling for item readers in chunk steps. It is
referenced from the <code>listener</code> element inside the <code>step</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>SkipProcessListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts
skippable exception handling for item processors in chunk steps. It is
referenced from the <code>listener</code> element inside the <code>step</code> element.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>javax.batch.api.chunk.listener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>SkipWriteListener</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Intercepts
skippable exception handling for item writers in chunk steps. It is
referenced from the <code>listener</code> element inside the <code>step</code> element.</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><a id="BCGIFJBB"></a><a id="dependency-injection-in-batch-artifacts"></a></p>
</div>
</div>
<div class="sect2">
<h3 id="_dependency_injection_in_batch_artifacts">Dependency Injection in Batch Artifacts</h3>
<div class="paragraph">
<p>To ensure that Contexts and Dependency Injection (CDI) works in your
batch artifacts, follow these steps.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Define your batch artifact implementations as CDI named beans using
the <code>Named</code> annotation.</p>
<div class="paragraph">
<p>For example, define an item reader implementation in a chunk step as
follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">@Named("MyItemReaderImpl")
public class MyItemReaderImpl implements ItemReader {
/* ... Override the ItemReader interface methods ... */
}</code></pre>
</div>
</div>
</li>
<li>
<p>Provide a public, empty, no-argument constructor for your batch
artifacts.</p>
<div class="paragraph">
<p>For example, provide the following constructor for the artifact above:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">public MyItemReaderImpl() {}</code></pre>
</div>
</div>
</li>
<li>
<p>Specify the CDI name for the batch artifacts in the job definition
file, instead of using the fully qualified name of the class.</p>
<div class="paragraph">
<p>For example, define the step for the artifact above as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn"><step id="stepA" next="stepB">
<chunk>
<reader ref="MyItemReaderImpl"></reader>
...
</chunk>
</step></code></pre>
</div>
</div>
<div class="paragraph">
<p>This example uses the CDI name (<code>MyItemReaderImpl</code>) instead of the fully
qualified name of the class (<code>com.example.pkg.MyItemReaderImpl</code>) to
specify a batch artifact.</p>
</div>
</li>
<li>
<p>Ensure that your module is a CDI bean archive by annotating your
batch artifacts with the <code>javax.enterprise.context.Dependent</code> annotation
or by including an empty <code>beans.xml</code> deployment description with your
application. For example, the following batch artifact is annotated with
<code>@Dependent</code>:</p>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">@Dependent
@Named("MyItemReaderImpl")
public class MyItemReaderImpl implements ItemReader { ... }</code></pre>
</div>
</div>
<div class="paragraph">
<p>For more information on bean archives, see
<a href="cdi-adv001.html#CACDCFDE">Packaging CDI Applications</a> in
<a href="cdi-adv.html#GJEHI">Chapter 27, "Contexts and Dependency Injection
for Java EE: Advanced Topics"</a>.</p>
</div>
</li>
</ol>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 100%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div><div class="paragraph">
<p>Note:</p>
</div>
<div class="paragraph">
<p>Contexts and Dependency Injection (CDI) is required in order to access
context objects from the batch runtime in batch artifacts.</p>
</div></div></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>You may encounter the following errors if you do not follow this
procedure.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The batch runtime cannot locate some batch artifacts.</p>
</li>
<li>
<p>The batch artifacts throw null pointer exceptions when accessing
injected objects.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p><a id="BCGCJEEF"></a><a id="using-the-context-objects-from-the-batch-runtime"></a></p>
</div>
</div>
<div class="sect2">
<h3 id="_using_the_context_objects_from_the_batch_runtime">Using the Context Objects from the Batch Runtime</h3>
<div class="paragraph">
<p>The batch runtime provides context objects that implement the
<code>JobContext</code> and <code>StepContext</code> interfaces in the
<code>javax.batch.runtime.context</code> package. These objects are associated with
the current job and step, respectively, and enable you to do the
following:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Get information from the current job or step, such as its name,
instance ID, execution ID, batch status, and exit status</p>
</li>
<li>
<p>Set the user-defined exit status</p>
</li>
<li>
<p>Store user data</p>
</li>
<li>
<p>Get property values from the job or step definition</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>You can inject context objects from the batch runtime inside batch
artifact implementations like item readers, item processors, item
writers, batchlets, listeners, and so on. The following example
demonstrates how to access property values from the job definition file
in an item reader implementation:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-oac_no_warn" data-lang="oac_no_warn">@Dependent
@Named("MyItemReaderImpl")
public class MyItemReaderImpl implements ItemReader {
@Inject
JobContext jobCtx;
public MyItemReaderImpl() {}
@Override
public void open(Serializable checkpoint) throws Exception {
String fileName = jobCtx.getProperties()
.getProperty("log_file_name");
...
}
...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>See <a href="#BCGIFJBB">Dependency Injection in Batch Artifacts</a> for
instructions on how to define your batch artifacts to use dependency
injection.</p>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 100%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div><div class="paragraph">
<p><strong>Note</strong>:</p>
</div>
<div class="paragraph">
<p>Do not access batch context objects inside artifact constructors.</p>
</div>
<div class="paragraph">
<p>Because the job does not run until you submit it to the batch runtime,
the batch context objects are not available when CDI instantiates your
artifacts upon loading your application. The instantiation of these
beans fails and the batch runtime cannot find your batch artifacts when
your application submits the job.</p>
</div></div></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr />
<table width="90%" id="bottom-nav" cellspacing="0" cellpadding="0">
<colgroup>
<col width="12%"/>
<col width="12%"/>
<col width="*"/>
</colgroup>
<tr>
<td align="left">
<a href="batch-processing004.html">
<span class=" vector-font"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Previous</span>
</a>
</td>
<td align="left">
<a href="batch-processing006.html">
<span class="vector-font"><i class="fa fa-arrow-circle-right vector-font" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Next</span>
</a>
</td>
<td align="right">
<a href="toc.html">
<span class="vector-font"><i class="fa fa-list vector-font" aria-hidden="true"></i></span>
<span style="position:relative;top:-2px;">Contents</span>
</a>
</td>
</tr>
</table>
<span id="copyright">
<a href="img/cpyr.adoc">
<img src="img/oracle.gif" height="10px" alt="Oracle Logo" />
<span>Copyright © 2017, Oracle and/or its affiliates. All rights reserved.</span>
</a>
</span>
<!--<p align="center" class="beta">Beta Draft (Pre-General Availability)</p> -->
</body>
</html>