Class JobSynchronizationManager
java.lang.Object
org.springframework.batch.core.scope.context.JobSynchronizationManager
Central convenience class for framework use in managing the job scope context.
Generally only to be used by implementations of
Job
. N.B. it is the
responsibility of every Job
implementation to ensure that a JobContext
is available on every thread that might be involved in a job execution, including
worker threads from a pool.- Since:
- 3.0
- Author:
- Dave Syer, Jimmy Praet, Mahmoud Ben Hassine
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
close()
Method for unregistering the current context - should always and only be used by in conjunction with a matchingregister(JobExecution)
to ensure thatgetContext()
always returns the correct value.static JobContext
Getter for the current context if there is one, otherwise returnsnull
.static JobContext
register
(JobExecution JobExecution) 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.
-
Constructor Details
-
JobSynchronizationManager
public JobSynchronizationManager()
-
-
Method Details
-
getContext
Getter for the current context if there is one, otherwise returnsnull
.- Returns:
- the current
JobContext
ornull
if there is none (if one has not been registered for this thread).
-
register
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:
JobExecution
- the step context to register- Returns:
- a new
JobContext
or the current one if it has the sameJobExecution
-
close
public static void close()Method for unregistering the current context - should always and only be used by in conjunction with a matchingregister(JobExecution)
to ensure thatgetContext()
always returns the correct value. Does not callJobContext.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 toJobContext.close()
and then ensures thatclose()
is also called in a finally block.
-