Adding a chunk step to a Java batch job

You can add a chunk step to the xml file of a Java™ batch job. You can read, process, and write individual items in the chunk step, and also restart the chunk step.

Before you begin

Complete the following tasks:
  • 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

Use the Job Specification Language (JSL) editor to create the chunk step. You will implement a reader node and a writer node for the chunk step. You can optionally create a processor node to process the input items. You can also optionally checkpoint the chunk step to restart it.

Procedure

  1. 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:
    1. In the Enterprise Explorer view, select your Java batch project that you created.
    2. Select src > META-INF > batch-jobs.
    3. Double-click the xml file for your Java batch job.

      The file displays in the JSL editor.

  2. Select the job node on the Overview tab; click Add.
  3. Select Step; click OK.
  4. Optional: Change the ID in the ID* field of the Details tab.
  5. Select the step node on the Overview tab; click Add.
  6. 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.

  7. Implement the reader node.
    1. On the Overview tab, click the reader node.

      The Details tab for the reader node displays.

    2. 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.
        1. Click the reference link on the Details tab.

          The Create Item Reader Class wizard displays.

        2. In the Java package field, specify the name of the package.
        3. In the Class name field, specify the name of the class.
        4. Optional: In the Super class field, specify the name of the super class or select Use abstract Java Batch class as superclass.
        5. Optional: In the Interfaces field, add more interfaces for the class to implement.
        6. 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.
        7. Click Finish.
      • Use an existing reader class to implement the chunk step.
        1. Click Browse on the Details tab.
        2. Search for classes by name by selecting Search for classes and then typing the class name.
        3. Select the class name from Matching items.
        4. 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.
        5. Click OK.
  8. Implement the writer node.
    1. On the Overview tab, click the writer node.

      The Details tab for the writer node displays.

    2. 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.
        1. 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.

        2. In the Java package field, specify the name of the package.
        3. In the Class name field, specify the name of the class.
        4. Optional: In the Super class field, specify the name of the super class or select Use abstract Java Batch class as superclass.
        5. Optional: In the Interfaces field, add more interfaces for the class to implement.
        6. 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.
        7. Click Finish.
      • 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.

        1. Click Browse on the Details tab.
        2. Search for classes by name by selecting Search for classes and then typing the class name.
        3. Select the class name from Matching items.
        4. 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.
        5. Click OK.
  9. Optional: Implement the processor node for the chunk node.

    The processor node is used to process inputs to the chunk step.

    1. Select the chunk node on the Overview tab; click Add.
    2. Select Processor; click OK.

      On the Overview tab of the JSL editor, the processor node displays as a child of the chunk node.

    3. 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.

    4. In the Java package field, specify the name of the package.
    5. In the Class name field, specify the name of the class.
    6. Optional: In the Super class field, specify the name of the super class.
    7. Optional: In the Interfaces field, add more interfaces for the class to implement.
    8. 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.
    9. Click Finish.
  10. 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.

    1. Checkpoint the chunk node after a specified number of records in the chunk are processed.
      1. Select Item for the checkpoint policy
      2. Specify the number of items to process per chunk by providing a value for Item count.
      3. Specify the amount of time that passes before a checkpoint is taken by providing a value for time-limit.
    2. Checkpoint the node that is based on a checkpoint algorithm.
      1. Select Custom for the checkpoint policy.
      2. On the Overview tab, click Add.
      3. Select Checkpoint algorithm; click OK.

        The Details tab for Checkpoint algorithm displays.

      4. 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.
          1. 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.

          2. In the Java package field, specify the name of the package.
          3. In the Class name field, specify the name of the class.
          4. Optional: In the Super class field, specify the name of the super class.
          5. Optional: In the Interfaces field, add more interfaces for the class to implement.
          6. 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.
          7. Click Finish.
        • 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.

          1. Click Browse on the Details tab.
          2. Search for classes by name by selecting Search for classes and then typing the class name.
          3. Select the class name from Matching items.
          4. 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.
          5. Click OK.
  11. Click Finish.

Results

You created a chunk step for a Java batch job. You implemented the reading and writing of items for the chunk step and optionally implemented processing of the input items. You also optionally implemented checkpoints for the chunk step so that you can restart the step.

Feedback