Java Reference
In-Depth Information
</beans:beans>
SystemCommandTasklet
The last type of Tasklet implementation that Spring Batch provides is
org.springframework.batch.core.step.tasklet.SystemCommandTasklet . This tasklet is used to—you
guessed it—execute a system command! The system command specified is executed asynchronously.
Because of this, the timeout value (in milliseconds) as shown in Listing 4-27 is important. The
interruptOnCancel attribute in the listing is optional but indicates to Spring Batch whether to kill the
thread the system process is associated with if the job exits abnormally.
Listing 4-27. Using SystemCommandTasklet
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns=" http://www.springframework.org/schema/batch"
xmlns:beans=" http://www.springframework.org/schema/beans"
xmlns:xsi= http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<beans:import resource="../launch-context.xml" />
<beans:bean id="tempFileDeletionCommand"
class="org.springframework.batch.core.step.tasklet.SystemCommandTasklet">
<beans:property name="command" value="rm - rf /temp.txt " />
<beans:property name="timeout" value="5000" />
<beans:property name="interruptOnCancel" value="true" />
</beans:bean>
<job id="systemCommandJob">
<step id="step1">
<tasklet ref="tempFileDeletionCommand" />
</step>
</job>
</beans:beans>
SystemCommandTasklet allows you to configure a number of parameters that can have an effect on
how a system command executes. Listing 4-28 shows a more robust example.
Listing 4-28. Using SystemCommandTasklet with Full Environment Configuration
<beans:bean id="touchCodeMapper"
class="org.springframework.batch.core.step.tasklet.SimpleSystemProcessExitCodeMapper"/>
<beans:bean id="taskExecutor"
class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
<beans:bean id="robustFileDeletionCommand"
class="org.springframework.batch.core.step.tasklet.SystemCommandTasklet">
 
Search WWH ::




Custom Search