Class 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 of Step. N.B. it is the responsibility of every Step implementation to ensure that a StepContext 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
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and TypeMethodDescription
      static voidclose()
      Method for unregistering the current context - should always and only be used by in conjunction with a matching register(StepExecution) to ensure that getContext() always returns the correct value.
      static StepContextgetContext()
      Getter for the current context if there is one, otherwise returns null.
      static StepContextregister​(StepExecution stepExecution)
      Register a context with the current thread - always put a matching close() call in a finally block to ensure that the correct context is available in the enclosing block.
      static StepContextregister​(StepExecution stepExecution, BatchPropertyContext propertyContext)
      Register a context with the current thread - always put a matching close() call in a finally block to ensure that the correct context is available in the enclosing block.
      static voidrelease()
      A convenient "deep" close operation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StepSynchronizationManager

        public StepSynchronizationManager()
    • Method Detail

      • getContext

        @Nullable
        public static StepContext getContext()
        Getter for the current context if there is one, otherwise returns null.
        Returns:
        the current StepContext or null 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 matching close() 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 same StepExecution
      • register

        public static StepContext register​(StepExecution stepExecution,
                                           BatchPropertyContext propertyContext)
        Register a context with the current thread - always put a matching close() call in a finally block to ensure that the correct context is available in the enclosing block.
        Parameters:
        stepExecution - the step context to register
        propertyContext - an instance of BatchPropertyContext to be used by the StepSynchronizationManager.
        Returns:
        a new StepContext or the current one if it has the same StepExecution
      • close

        public static void close()
        Method for unregistering the current context - should always and only be used by in conjunction with a matching register(StepExecution) to ensure that getContext() always returns the correct value. Does not call StepContext.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 of close() if the step execution for the current context is ending. Delegates to StepContext.close() and then ensures that close() is also called in a finally block.