Adding a chunk step to a Java batch job
Before you begin
- Install the Java batch feature for WebSphere® Application Server Developer Tools for Eclipse. This feature is an optional. You can install it from Help > Install WebSphere Software.
- Create a Java batch project.
- Create a Java batch job in the Java batch project.
About this task
Procedure
- In the Job Specification Language (JSL) editor, open the xml file for your Java batch job.
The JSL editor opens automatically if you click Finish when you create a Java batch job. An xml file with the same name as the batch job displays in the JSL editor.
If you are adding a step to an existing Java batch job xml file, complete the following steps to open the xml file in the JSL editor:- In the Enterprise Explorer view, select your Java batch project that you created.
- Select src > META-INF > batch-jobs.
- Double-click the xml file for your Java batch job.
The file displays in the JSL editor.
- Select the job node on the Overview tab; click Add.
- Select Step; click OK.
- Optional: Change the ID in the ID* field of the Details tab.
- Select the step node on the Overview tab; click Add.
- Select Chunk; click OK.
On the overview tab of the JSL editor, the chunk node displays as a child of the step. A reader node and a writer node display as children of the chunk node.
- Implement the reader node.
- On the Overview tab, click the reader node.
The Details tab for the reader node displays.
- Create or include a reader class to implement the reader node.
You can create a reader class for your project, include a reader class from another step within your project, or include a reader class from a chunk step in another project. Complete one of the following tasks:
- Create a reader class for your chunk step.
- Click the reference link on the Details tab.
The Create Item Reader Class wizard displays.
- In the Java package field, specify the name of the package.
- In the Class name field, specify the name of the class.
- Optional: In the Super class field, specify the name of the super class or select Use abstract Java Batch class as superclass.
- Optional: In the Interfaces field, add more interfaces for the class to implement.
- For Batch artifact loading options, accept the default value of
Use the fully qualified name of the class.
- If you select the Use the fully qualified name of the class option, the runtime environment treats the batch artifact reference as a class name and loads the reference through the thread context class loader. The loading is done to resolve a batch artifact reference when the archive loader returns null for this reference.
- If you select the Use context and dependency injection (CDI) option, the runtime environment uses the CDI implementation-specific loader to resolve the batch artifact reference by using the bean name that you specify.
- If you select the Add the class to the batch.xml file option, the runtime environment uses the archive loader to resolve the reference by looking for the specified identifier in the batch.xml file.
- Click Finish.
- Click the reference link on the Details tab.
- Use an existing reader class to implement the chunk step.
- Click Browse on the Details tab.
- Search for classes by name by selecting Search for classes and then typing the class name.
- Select the class name from Matching items.
- As an alternative to the search, if a batch.xml file exists, select Browse entries in batch.xml and then select one of the entries from the table.
- Click OK.
- Create a reader class for your chunk step.
- On the Overview tab, click the reader node.
- Implement the writer node.
- On the Overview tab, click the writer node.
The Details tab for the writer node displays.
- Create or include a writer class to implement the writer node. You can create a writer class for your project, include a writer class from another step within your project, or include a writer class from a chunk step in another project. Complete one of the following tasks:
- Create a writer class for your chunk step.
- Click the reference link on the Details tab.
The Create Item Writer Class wizard displays.
The following descriptions about the Create Item Writer Class wizard are the same as those descriptions for the Create Item Reader Class wizard. The information is repeated here in context.
- In the Java package field, specify the name of the package.
- In the Class name field, specify the name of the class.
- Optional: In the Super class field, specify the name of the super class or select Use abstract Java Batch class as superclass.
- Optional: In the Interfaces field, add more interfaces for the class to implement.
- For Batch artifact loading options, accept the default value of
Use the fully qualified name of the class.
- If you select the Use the fully qualified name of the class option, the runtime environment treats the batch artifact reference as a class name and loads the reference through the thread context class loader. The loading is done to resolve a batch artifact reference when the archive loader returns null for this reference.
- If you select the Use context and dependency injection (CDI) option, the runtime environment uses the CDI implementation-specific loader to resolve the batch artifact reference by using the bean name that you specify.
- If you select the Add the class to the batch.xml file option, the runtime environment uses the archive loader to resolve the reference by looking for the specified identifier in the batch.xml file.
- Click Finish.
- Click the reference link on the Details tab.
- Use an existing writer class to implement the chunk step.
The following steps are the same as those described in the reader class previously. The information is repeated here in context.
- Click Browse on the Details tab.
- Search for classes by name by selecting Search for classes and then typing the class name.
- Select the class name from Matching items.
- As an alternative to the search, if a batch.xml file exists, select Browse entries in batch.xml and then select one of the entries from the table.
- Click OK.
- Create a writer class for your chunk step.
- On the Overview tab, click the writer node.
- Optional: Implement the processor node for the chunk node.
The processor node is used to process inputs to the chunk step.
- Select the chunk node on the Overview tab; click Add.
- Select Processor; click OK.
On the Overview tab of the JSL editor, the processor node displays as a child of the chunk node.
- Click the reference link on the Details tab.
The Create Item Processor Class wizard displays
The following descriptions about the Create Item Processor Class wizard are the same as those descriptions for the Create Item Reader Class wizard. The information is repeated here in context.
- In the Java package field, specify the name of the package.
- In the Class name field, specify the name of the class.
- Optional: In the Super class field, specify the name of the super class.
- Optional: In the Interfaces field, add more interfaces for the class to implement.
- For Batch artifact loading options, accept the default value of
Use the fully qualified name of the class.
- If you select the Use the fully qualified name of the class option, the runtime environment treats the batch artifact reference as a class name and loads the reference through the thread context class loader. The loading is done to resolve a batch artifact reference when the archive loader returns null for this reference.
- If you select the Use context and dependency injection (CDI) option, the runtime environment uses the CDI implementation-specific loader to resolve the batch artifact reference by using the bean name that you specify.
- If you select the Add the class to the batch.xml file option, the runtime environment uses the archive loader to resolve the reference by looking for the specified identifier in the batch.xml file.
- Click Finish.
- Optional: Checkpoint the chunk node so that you can restart the node.
You can either checkpoint the chunk node after a specified number of records in the chunk are processed or according to a checkpoint algorithm.
- Checkpoint the chunk node after a specified number of records in the chunk are processed.
- Select Item for the checkpoint policy
- Specify the number of items to process per chunk by providing a value for Item count.
- Specify the amount of time that passes before a checkpoint is taken by providing a value for time-limit.
- Checkpoint the node that is based on a checkpoint algorithm.
- Select Custom for the checkpoint policy.
- On the Overview tab, click Add.
- Select Checkpoint algorithm; click OK.
The Details tab for Checkpoint algorithm displays.
- Create or include a checkpoint algorithm class to implement the checkpoint algorithm.You can create a new checkpoint algorithm class for your chunk step, include a checkpoint algorithm class from another step within your project, or include a checkpoint algorithm class from a checkpoint algorithm step in another project. Complete one of the following sets of steps:
- Create a checkpoint algorithm class to implement the checkpoint algorithm.
- Click the reference link on the Details tab.
The Create Checkpoint Algorithm Class wizard displays.
The following descriptions about the Create Checkpoint Algorithm Class wizard are the same as those descriptions for the Create Item Reader Class wizard. The information is repeated here in context.
- In the Java package field, specify the name of the package.
- In the Class name field, specify the name of the class.
- Optional: In the Super class field, specify the name of the super class.
- Optional: In the Interfaces field, add more interfaces for the class to implement.
- For Batch artifact loading options, accept the default value of
Use the fully qualified name of the class.
- If you select the Use the fully qualified name of the class option, the runtime environment treats the batch artifact reference as a class name and loads the reference through the thread context class loader. The loading is done to resolve a batch artifact reference when the archive loader returns null for this reference.
- If you select the Use context and dependency injection (CDI) option, the runtime environment uses the CDI implementation-specific loader to resolve the batch artifact reference by using the bean name that you specify.
- If you select the Add the class to the batch.xml file option, the runtime environment uses the archive loader to resolve the reference by looking for the specified identifier in the batch.xml file.
- Click Finish.
- Click the reference link on the Details tab.
- Use an existing checkpoint algorithm class to implement the checkpoint algorithm.
The following steps are the same as those described in the reader class previously. The information is repeated here in context.
- Click Browse on the Details tab.
- Search for classes by name by selecting Search for classes and then typing the class name.
- Select the class name from Matching items.
- As an alternative to the search, if a batch.xml file exists, select Browse entries in batch.xml and then select one of the entries from the table.
- Click OK.
- Create a checkpoint algorithm class to implement the checkpoint algorithm.
- Checkpoint the chunk node after a specified number of records in the chunk are processed.
- Click Finish.
Results
Feedback