Java Reference
In-Depth Information
<step id="step1" parent="copyStep" />
Although typically you define the size of a chunk based on a hard number configured with the
commit-interval attribute as configured in Listing 4-34, that isn't always a robust enough option. Say
that you have a job that needs to process chunks that aren't all the same size (processing all transactions
for an account in a single transaction, for example). Spring Batch provides the ability to
programmatically define when a chunk is complete via an implementation of the
org.springframework.batch.repeat.CompletionPolicy interface.
The CompletionPolicy interface allows the implementation of decision logic to decide if a given
chunk is complete. Spring Batch comes with a number of implementations of this interface. By default it
uses org.springframework.batch.repeat.policy.SimpleCompletionPolicy , which counts the number of
items processed and flags a chunk complete when the configured threshold is reached. Another out-of-
the-box implementation is org.springframework.batch.repeat.policy.TimeoutTerminationPolicy . This
allows you to configure a timeout on a chunk so that it may exit gracefully after a given amount of time.
What does “exit gracefully” mean in this context? It means that the chunk is considered complete and all
transaction processing continues normally.
As you can undoubtedly deduce, there are few times when a timeout by itself is enough to
determine when a chunk of processing will be complete. TimeoutTerminationPolicy is more likely to be
used as part of org.springframework.batch.repeat.policy.CompositeCompletionPolicy . This policy lets
you configure multiple polices that determine whether a chunk has completed. When you use
CompositeCompletionPolicy , if any of the policies consider a chunk complete, then the chunk is flagged
as complete. Listing 4-35 shows an example of using a timeout of 3 milliseconds along with the normal
commit count of 200 items to determine if a chunk is complete.
Listing 4-35. Using a Timeout Along With a Regular Commit Count
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns=""
<beans:import resource="../launch-context.xml" />
<beans:bean id="inputFile"
class="" scope="step">
<beans:constructor-arg value="#{jobParameters[inputFile]}" />
<beans:bean id="outputFile"
class="" scope="step">
<beans:constructor-arg value="#{jobParameters[outputFile]}" />
Search WWH ::

Custom Search