public final class DefaultThreadService extends AbstractService implements ThreadService
ThreadService.ThreadContext| Constructor and Description | 
|---|
| DefaultThreadService() | 
| Modifier and Type | Method and Description | 
|---|---|
| void | dispose()Performs any needed cleanup of the object's services, in preparation for
 the object being retired (e.g., to make garbage collection possible). | 
| ExecutorService | getExecutorService()Gets the  ExecutorServiceobject used whenThreadService.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  Contextof 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
  ThreadService.invoke(Runnable)andThreadService.queue(Runnable). | 
| Thread | newThread(Runnable r) | 
| void | queue(Runnable code)Queues the given code for later execution in a special dispatch thread,
 returning immediately. | 
| <V> Future<V> | queue(String id,
     Callable<V> code)Queues the given code for later execution in a dispatch thread associated
 with the specified ID, returning immediately. | 
| Future<?> | queue(String id,
     Runnable code)Queues the given code for later execution in a dispatch thread associated
 with the specified ID, returning immediately. | 
| <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  ExecutorServiceobject used whenThreadService.run(java.util.concurrent.Callable<V>)is called. | 
getContext, setContext, toStringgetInfo, getPriority, setInfo, setPrioritycontextclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitinitialize, registerEventHandlersgetIdentifier, logcontext, getContext, setContextcompareTo, getPriority, setPrioritygetInfo, setInfogetLocationgetVersionpublic <V> Future<V> run(Callable<V> code)
ThreadServicerun in interface ThreadServicecode - 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).public Future<?> run(Runnable code)
ThreadServicerun in interface ThreadServicecode - The code to execute.Future that can be used to block until the execution has
         finished. Call Future.get() to do so.public ExecutorService getExecutorService()
ThreadServiceExecutorService object used when ThreadService.run(java.util.concurrent.Callable<V>) is called.getExecutorService in interface ThreadServiceExecutorService, or null if an ExecutorService
         is not used in this ThreadService implementation.public void setExecutorService(ExecutorService executor)
ThreadServiceExecutorService object used when ThreadService.run(java.util.concurrent.Callable<V>) is called.setExecutorService in interface ThreadServiceexecutor - The ExecutorService for this ThreadService
          to use internally for ThreadService.run(java.util.concurrent.Callable<V>) calls.public boolean isDispatchThread()
ThreadServiceThreadService.invoke(Runnable) and ThreadService.queue(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.
isDispatchThread in interface ThreadServicepublic void invoke(Runnable code) throws InterruptedException, InvocationTargetException
ThreadServiceIn 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.
invoke in interface ThreadServicecode - The code to execute.InterruptedException - If the code execution is interrupted.InvocationTargetException - If an uncaught exception occurs in the
           code during execution.public void queue(Runnable code)
ThreadServiceIn 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.
queue in interface ThreadServicecode - The code to execute.public Future<?> queue(String id, Runnable code)
ThreadServicequeue in interface ThreadServiceid - The ID designating which dispatch thread will execute the code.code - The code to execute.Future whose Future.get() method blocks until the
         queued code has completed executing and returns null.ExecutorService.submit(Runnable)public <V> Future<V> queue(String id, Callable<V> code)
ThreadServicequeue in interface ThreadServiceid - The ID designating which dispatch thread will execute the code.code - The code to execute.Future whose Future.get() method blocks until the
         queued code has completed executing and returns the result of the
         execution.ExecutorService.submit(Callable)public Thread getParent(Thread thread)
ThreadServiceThis works only on threads which the thread service knows about, of course.
getParent in interface ThreadServicethread - the managed thread, null refers to the current threadThreadService to spawn the
         specified threadpublic ThreadService.ThreadContext getThreadContext(Thread thread)
ThreadServiceContext of the given thread.getThreadContext in interface ThreadServicethread - 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.public void dispose()
Disposabledispose in interface Disposablepublic Thread newThread(Runnable r)
newThread in interface ThreadFactoryCopyright © 2009–2022 SciJava. All rights reserved.