public interface ThreadService extends SciJavaService, ThreadFactory
Modifier and Type | Interface and Description |
---|---|
static class |
ThreadService.ThreadContext |
Modifier and Type | Method and Description |
---|---|
ExecutorService |
getExecutorService()
Gets the
ExecutorService object used when run(java.util.concurrent.Callable<V>) is called. |
Thread |
getParent(Thread thread)
Returns the thread that called the specified thread.
|
ThreadService.ThreadContext |
getThreadContext(Thread thread)
Analyzes the
Context of the given thread. |
void |
invoke(Runnable code)
Executes the given code in a special dispatch thread, blocking until
execution is complete.
|
boolean |
isDispatchThread()
Gets whether the current thread is a dispatch thread for use with
invoke(java.lang.Runnable) and queue(java.lang.Runnable) . |
void |
queue(Runnable code)
Queues the given code for later execution in a special dispatch thread.
|
<V> Future<V> |
run(Callable<V> code)
Asynchronously executes the given code in a new thread, as decided by the
thread service.
|
Future<?> |
run(Runnable code)
Asynchronously executes the given code in a new thread, as decided by the
thread service.
|
void |
setExecutorService(ExecutorService executor)
Sets the
ExecutorService object used when run(java.util.concurrent.Callable<V>) is called. |
initialize, registerEventHandlers
context, getContext, setContext
getPriority, setPriority
compareTo
getInfo, setInfo
dispose
newThread
<V> Future<V> run(Callable<V> code)
code
- The code to execute.Future
that will contain the result once the execution
has finished. Call Future.get()
to access to the return
value (which will block until execution has completed).Future<?> run(Runnable code)
code
- The code to execute.Future
that can be used to block until the execution has
finished. Call Future.get()
to do so.ExecutorService getExecutorService()
ExecutorService
object used when run(java.util.concurrent.Callable<V>)
is called.ExecutorService
, or null if an ExecutorService
is not used in this ThreadService
implementation.void setExecutorService(ExecutorService executor)
ExecutorService
object used when run(java.util.concurrent.Callable<V>)
is called.executor
- The ExecutorService
for this ThreadService
to use internally for run(java.util.concurrent.Callable<V>)
calls.UnsupportedOperationException
- if this ThreadService
does
not use an ExecutorService
to handle run(java.util.concurrent.Callable<V>)
calls.boolean isDispatchThread()
invoke(java.lang.Runnable)
and queue(java.lang.Runnable)
.
In the case of AWT-based applications (e.g., Java on the desktop), this is typically the AWT Event Dispatch Thread (EDT). However, ultimately the behavior is implementation-dependent.
void invoke(Runnable code) throws InterruptedException, InvocationTargetException
In the case of AWT-based applications (e.g., Java on the desktop), this is typically the AWT Event Dispatch Thread (EDT). However, ultimately the behavior is implementation-dependent.
code
- The code to execute.InterruptedException
- If the code execution is interrupted.InvocationTargetException
- If an uncaught exception occurs in the
code during execution.void queue(Runnable code)
In the case of AWT-based applications (e.g., Java on the desktop), this is typically the AWT Event Dispatch Thread (EDT). However, ultimately the behavior is implementation-dependent.
code
- The code to execute.Thread getParent(Thread thread)
This works only on threads which the thread service knows about, of course.
thread
- the managed thread, null refers to the current threadThreadService
to spawn the
specified threadThreadService.ThreadContext getThreadContext(Thread thread)
Context
of the given thread.thread
- The thread to analyze.Context
. Either:
ThreadService.ThreadContext.SAME
- The thread was spawned by this
very thread service, and thus shares the same Context
.ThreadService.ThreadContext.OTHER
- The thread was spawned by a
different thread service, and thus has a different Context
.
ThreadService.ThreadContext.NONE
- It is unknown what spawned the
thread, so it is effectively Context
-free.Copyright © 2009–2015 SciJava. All rights reserved.