Class SubjectCallable<V>

  • All Implemented Interfaces:
    <V>

    public class SubjectCallable<V>
    extends 
    implements <V>
    A SubjectCallable associates a Subject with a target/delegate to ensure proper Subject thread-state management when the Callable executes. This ensures that any calls to SecurityUtils.getSubject() during the target Callable's execution still work correctly even if the Callable executes on a different thread than the one that created it. This allows Subject access during asynchronous operations.

    When instances of this class execute (typically via a ), the following occurs:

    1. The specified Subject any of its associated thread state is first bound to the thread that executes the Callable.
    2. The delegate/target Callable is
    3. The previous thread state that might have existed before the Subject was bound is fully restored

    This behavior ensures that the thread that executes this Callable, which is often a different thread than the one that created the instance, retains a Subject to support SecurityUtils.getSubject() invocations. It also guarantees that the running thread remains 'clean' in any thread-pooled environments.

    Usage

    This is typically considered a support class and is not often directly referenced. Most people prefer to use the Subject.associateWith method, which will automatically return an instance of this class.

    An even more convenient alternative is to use a SubjectAwareExecutorService, which transparently uses instances of this class.

    Since:
    1.0
    See Also:
    Subject.associateWith(Callable), SubjectAwareExecutorService
    • Field Detail

    • Constructor Detail

      • SubjectCallable

        public SubjectCallable​(Subject subject,
                               <V> delegate)
      • SubjectCallable

        protected SubjectCallable​(ThreadState threadState,
                                  <V> delegate)
    • Method Detail

      • call

        public V call()
               throws 
        Specified by:
         in interface <V>
        Throws:
      • doCall

        protected <V> target)
                    throws 
        Throws: