Class SynchronizedItemStreamWriter<T>
java.lang.Object
org.springframework.batch.item.support.SynchronizedItemStreamWriter<T>
- Type Parameters:
T- type of object being written
- All Implemented Interfaces:
ItemStream,ItemStreamWriter<T>,ItemWriter<T>
An
ItemStreamWriter decorator with a synchronized
write() method.
This decorator is useful when using a non thread-safe item writer in a multi-threaded
step. Typical delegate examples are the
JsonFileItemWriter and
StaxEventItemWriter.
It should be noted that synchronizing writes might introduce some performance
degradation, so this decorator should be used wisely and only when necessary. For
example, using a FlatFileItemWriter in a multi-threaded step does NOT require synchronizing writes, so
using this decorator in such use case might be counter-productive.
- Author:
- Dimitrios Liapis, Mahmoud Ben Hassine
-
Constructor Summary
ConstructorsConstructorDescriptionSynchronizedItemStreamWriter(ItemStreamWriter<T> delegate) Create a newSynchronizedItemStreamWriterwith the given delegate. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()If any resources are needed for the stream to operate they need to be destroyed here.voidopen(ExecutionContext executionContext) Open the stream for the providedExecutionContext.voidsetDelegate(ItemStreamWriter<T> delegate) Set the delegateItemStreamWriter.voidupdate(ExecutionContext executionContext) Indicates that the execution context provided during open is about to be saved.voidThis method delegates to thewritemethod of thedelegate.
-
Constructor Details
-
SynchronizedItemStreamWriter
Create a newSynchronizedItemStreamWriterwith the given delegate.- Parameters:
delegate- the item writer to use as a delegate- Since:
- 6.0
-
-
Method Details
-
setDelegate
Set the delegateItemStreamWriter.- Parameters:
delegate- the delegate to set
-
write
This method delegates to thewritemethod of thedelegate.- Specified by:
writein interfaceItemWriter<T>- Parameters:
items- of items to be written. Must not benull.- Throws:
Exception- if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.
-
open
Description copied from interface:ItemStreamOpen the stream for the providedExecutionContext.- Specified by:
openin interfaceItemStream- Parameters:
executionContext- current step'sExecutionContext. Will be the executionContext from the last run of the step on a restart.- Throws:
ItemStreamException
-
update
Description copied from interface:ItemStreamIndicates that the execution context provided during open is about to be saved. If any state is remaining, but has not been put in the context, it should be added here.- Specified by:
updatein interfaceItemStream- Parameters:
executionContext- to be updated- Throws:
ItemStreamException
-
close
Description copied from interface:ItemStreamIf any resources are needed for the stream to operate they need to be destroyed here. Once this method has been called all other methods (except open) may throw an exception.- Specified by:
closein interfaceItemStream- Throws:
ItemStreamException
-