- All Known Implementing Classes:
SwingDispatcher
Provides access to a dispatch context: a confined execution context which results must be handed back to, and which must not be blocked. On UI platforms this is the UI thread, the Swing event dispatch thread or the Android main looper, but nothing here requires a user interface.
A context is not necessarily a fixed thread. Implementations may bind one to the calling thread for
the duration of a request, as web frameworks providing a per-session context do, which is why
bound() asks whether a context is bound here rather than which thread is running.
The implementation is provided via ServiceLoader, defaulting to SYNCHRONOUS when
none is available.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DispatcherADispatcherwithout a dispatch context, running tasks on the calling thread. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbound()Returns true if a dispatch context is bound to the caller, that is, if this is the context results must be handed back to and which must not be blocked.executor()Returns anExecutorrunning tasks on the dispatch context, resolved for the caller.static Dispatcherinstance()Returns theDispatcherimplementation, as provided viaServiceLoader, orSYNCHRONOUSin case no implementation is available.
-
Field Details
-
SYNCHRONOUS
ADispatcherwithout a dispatch context, running tasks on the calling thread.Used when no implementation is available, and useful for testing.
-
-
Method Details
-
executor
Executor executor()Returns an
Executorrunning tasks on the dispatch context, resolved for the caller.Must be called where a context is bound, see
bound(), so that implementations binding a context per request or session resolve the right one.- Returns:
- an
Executorrunning tasks on the dispatch context
-
bound
boolean bound()Returns true if a dispatch context is bound to the caller, that is, if this is the context results must be handed back to and which must not be blocked.
This reports a fact, not a recommendation. Whether to hand work off on the strength of it is left to the caller, some always do so regardless.
- Returns:
- true if a dispatch context is bound to the caller
-
instance
Returns theDispatcherimplementation, as provided viaServiceLoader, orSYNCHRONOUSin case no implementation is available.- Returns:
- the
Dispatcherimplementation to use
-