Class SubjectAwareExecutorService

java.lang.Object
org.apache.shiro.concurrent.SubjectAwareExecutor
org.apache.shiro.concurrent.SubjectAwareExecutorService
All Implemented Interfaces:
Executor, ExecutorService
Direct Known Subclasses:
SubjectAwareScheduledExecutorService

ExecutorService implementation that will automatically first associate any argument Runnable or Callable instances with the currently available subject and then dispatch the Subject-enabled runnable or callable to an underlying delegate ExecutorService instance. The principle is the same as the parent SubjectAwareExecutor class, but enables the richer ExecutorService API.

This is a simplification for applications that want to execute code as the currently executing Subject on another thread, but don't want or need to call the Subject.associateWith(Runnable) or Subject.associateWith(Callable) methods and dispatch them to a Thread manually. This simplifies code and reduces Shiro dependencies across application source code.

Consider this code that could be repeated in many places across an application:

 Callable applicationWork = //instantiate or acquire Callable from somewhere
 Subject subject = SecurityUtils.
 getSubject();
 Callable work = subject.associateWith(applicationWork);
 anExecutorService.submit(work);
 
Instead, if the ExecutorService instance used at runtime is an instance of this class (which delegates to the target ExecutorService that you want), all places in code like the above reduce to this:
 Callable applicationWork = //instantiate or acquire Callable from somewhere
 anExecutorService.submit(work);
 
Notice there is no use of the Shiro API in the 2nd code block, encouraging the principle of loose coupling across your codebase.
Since:
1.0