-
Book Overview & Buying
-
Table Of Contents
SPRING COOKBOOK
By :
A step can consist of just an execution of a system command. Spring Batch provides a convenient class for this, SystemCommandTasklet.
We'll use the job defined in the Creating a job recipe.
In Spring Batch's configuration file, add a SystemCommandTasklet bean. Declare the system command to be executed (here, we used the touch Unix command to create an empty file), the directory to execute it from, and the maximum time allowed for its execution:
@Bean
public SystemCommandTasklet task1() {
SystemCommandTasklet tasklet = new SystemCommandTasklet();
tasklet.setCommand("touch test.txt");
tasklet.setWorkingDirectory("/home/merlin");
tasklet.setTimeout(5000);
return tasklet;
}The SystemCommandTasklet class will execute a command from the working directory and kill the process if it exceeds the timeout value.
For a more advanced use of system commands (for example, to get the output of the system command) extend...
Change the font size
Change margin width
Change background colour