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>
,org.springframework.beans.factory.InitializingBean
public class SynchronizedItemStreamWriter<T>
extends Object
implements ItemStreamWriter<T>, org.springframework.beans.factory.InitializingBean
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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 providedExecutionContext
.void
setDelegate
(ItemStreamWriter<T> delegate) Set the delegateItemStreamWriter
.void
update
(ExecutionContext executionContext) Indicates that the execution context provided during open is about to be saved.void
This method delegates to thewrite
method of thedelegate
.
-
Constructor Details
-
SynchronizedItemStreamWriter
public SynchronizedItemStreamWriter()
-
-
Method Details
-
setDelegate
Set the delegateItemStreamWriter
.- Parameters:
delegate
- the delegate to set
-
write
This method delegates to thewrite
method of thedelegate
.- Specified by:
write
in 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:ItemStream
Open the stream for the providedExecutionContext
.- Specified by:
open
in 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:ItemStream
Indicates 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:
update
in interfaceItemStream
- Parameters:
executionContext
- to be updated- Throws:
ItemStreamException
-
close
Description copied from interface:ItemStream
If 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:
close
in interfaceItemStream
- Throws:
ItemStreamException
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-