Creating a job

We'll create a job that will simply execute some Java code. It will be a job with only one step. The step will be a Tasklet object (a single task, as opposed to a read-process-write step, which we'll cover later). We will execute this job in two different ways in the next two recipes.

How to do it…

Create a Tasklet class, which you will use to define a step and the job:

  1. Create the Task1 class implementing Tasklet:
    public class Task1 implements Tasklet {    
    
    }
  2. In the Task1 class, add an execute() method with the code to be executed for the job:
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { System.out.println("Starting job.."); // ... your code System.out.println("Job done.."); return ...

Get Spring Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.