Class StepSynchronizationManager
- java.lang.Object
- org.springframework.batch.core.scope.context.StepSynchronizationManager
public class StepSynchronizationManager extends java.lang.Object
Central convenience class for framework use in managing the step scope context. Generally only to be used by implementations ofStep
. N.B. it is the responsibility of everyStep
implementation to ensure that aStepContext
is available on every thread that might be involved in a step execution, including worker threads from a pool.- Author:
- Dave Syer, Michael Minella, Mahmoud Ben Hassine
Constructor Summary
Constructors Constructor Description StepSynchronizationManager()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
close()
Method for unregistering the current context - should always and only be used by in conjunction with a matchingregister(StepExecution)
to ensure thatgetContext()
always returns the correct value.static StepContext
getContext()
Getter for the current context if there is one, otherwise returnsnull
.static StepContext
register(StepExecution stepExecution)
Register a context with the current thread - always put a matchingclose()
call in a finally block to ensure that the correct context is available in the enclosing block.static StepContext
register(StepExecution stepExecution, BatchPropertyContext propertyContext)
Register a context with the current thread - always put a matchingclose()
call in a finally block to ensure that the correct context is available in the enclosing block.static void
release()
A convenient "deep" close operation.
Method Detail
getContext
@Nullable public static StepContext getContext()
Getter for the current context if there is one, otherwise returnsnull
.- Returns:
- the current
StepContext
ornull
if there is none (if one has not been registered for this thread).
register
public static StepContext register(StepExecution stepExecution)
Register a context with the current thread - always put a matchingclose()
call in a finally block to ensure that the correct context is available in the enclosing block.- Parameters:
stepExecution
- the step context to register- Returns:
- a new
StepContext
or the current one if it has the sameStepExecution
register
public static StepContext register(StepExecution stepExecution, BatchPropertyContext propertyContext)
Register a context with the current thread - always put a matchingclose()
call in a finally block to ensure that the correct context is available in the enclosing block.- Parameters:
stepExecution
- the step context to registerpropertyContext
- an instance ofBatchPropertyContext
to be used by the StepSynchronizationManager.- Returns:
- a new
StepContext
or the current one if it has the sameStepExecution
close
public static void close()
Method for unregistering the current context - should always and only be used by in conjunction with a matchingregister(StepExecution)
to ensure thatgetContext()
always returns the correct value. Does not callStepContext.close()
- that is left up to the caller because he has a reference to the context (having registered it) and only he has knowledge of when the step actually ended.
release
public static void release()
A convenient "deep" close operation. Call this instead ofclose()
if the step execution for the current context is ending. Delegates toStepContext.close()
and then ensures thatclose()
is also called in a finally block.