T - type of object being writtenpublic class SynchronizedItemStreamWriter<T> extends java.lang.Object implements ItemStreamWriter<T>, org.springframework.beans.factory.InitializingBean
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.
| Constructor and Description |
|---|
SynchronizedItemStreamWriter() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
void |
close()
If any resources are needed for the stream to operate they need to be destroyed here.
|
void |
open(ExecutionContext executionContext)
Open the stream for the provided
ExecutionContext. |
void |
setDelegate(ItemStreamWriter<T> delegate)
Set the delegate
ItemStreamWriter. |
void |
update(ExecutionContext executionContext)
Indicates that the execution context provided during open is about to be saved.
|
void |
write(java.util.List<? extends T> items)
This method delegates to the
write method of the delegate. |
public void setDelegate(ItemStreamWriter<T> delegate)
ItemStreamWriter.delegate - the delegate to setpublic void write(java.util.List<? extends T> items) throws java.lang.Exception
write method of the delegate.write in interface ItemWriter<T>items - items to be writtenjava.lang.Exception - if there are errors. The framework will catch the
exception and convert or rethrow it as appropriate.public void open(ExecutionContext executionContext) throws ItemStreamException
ItemStreamExecutionContext.open in interface ItemStreamexecutionContext - current step's ExecutionContext. Will be the
executionContext from the last run of the step on a restart.ItemStreamExceptionpublic void update(ExecutionContext executionContext) throws ItemStreamException
ItemStreamupdate in interface ItemStreamexecutionContext - to be updatedItemStreamExceptionpublic void close()
throws ItemStreamException
ItemStreamclose in interface ItemStreamItemStreamExceptionpublic void afterPropertiesSet()
throws java.lang.Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.lang.Exception