public class ThreadsExecutor extends AbstractExecutor
An executor that implements running the givenIProgressRunnables via a
new Thread.
The execute(IProgressRunnable, IProgressMonitor) method on this
class will create a new Thread (with name provided as result of
createThreadName(IProgressRunnable), that will run the
IProgressRunnable and set the result in the future returned from
execute(IProgressRunnable, IProgressMonitor).
Subclasses may extend the behavior of this ThreadsExecutor.
| Constructor and Description |
|---|
ThreadsExecutor() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
configureThreadForExecution(java.lang.Thread thread)
Configure the given thread prior to starting it.
|
protected AbstractFuture<?> |
createFuture(IProgressMonitor monitor)
Create an
AbstractFuture with the given IProgressMonitor. |
protected java.lang.Runnable |
createRunnable(ISafeProgressRunner runner,
IProgressRunnable<?> progressRunnable)
Create a runnable given an
IProgressRunnable and an
ISafeProgressRunner to run the runnable. |
protected java.lang.String |
createThreadName(IProgressRunnable<?> runnable) |
<ResultType> |
execute(IProgressRunnable<? extends ResultType> runnable,
IProgressMonitor monitor)
Execute the given
IProgressRunnable (i.e. call
IProgressRunnable.run(IProgressMonitor). |
executeprotected java.lang.String createThreadName(IProgressRunnable<?> runnable)
protected java.lang.Runnable createRunnable(ISafeProgressRunner runner, IProgressRunnable<?> progressRunnable)
IProgressRunnable and an
ISafeProgressRunner to run the runnable.runner - the safe progress runner to run the runnableprogressRunnable - the runnable to run.protected void configureThreadForExecution(java.lang.Thread thread)
Thread.setDaemon(boolean).thread - the thread to configureprotected AbstractFuture<?> createFuture(IProgressMonitor monitor)
AbstractFuture with the given IProgressMonitor.createFuture in class AbstractExecutormonitor - a progress monitor to associate with the future. May be
null.public <ResultType> IFuture<ResultType> execute(IProgressRunnable<? extends ResultType> runnable, IProgressMonitor monitor) throws java.lang.IllegalThreadStateException
IExecutor
Execute the given IProgressRunnable (i.e. call
IProgressRunnable.run(IProgressMonitor). Will return a non-
null instance of IFuture that allows clients to
inspect the state of the execution and retrieve any results via
IFuture.get() or IFuture.get(long).
Note that implementers may decide whether to invoke
IProgressRunnable.run(IProgressMonitor) asynchronously or
synchronously, but since IProgressRunnables are frequently going to be
longer-running operations, implementers should proceed carefully before
implementing with synchronous (blocking) invocation. Implementers should
typically implement via some non-blocking asynchronous invocation
mechanism, e.g. Threads, Jobs, ThreadPools etc.
execute in interface IExecutorexecute in class AbstractExecutorResultType - the type that will be returned by the
IProgressRunnable as well as the returned
IFuturerunnable - the IProgressRunnable to invoke. Must not be
null.monitor - any IProgressMonitor to be passed to the runnable. May
be null.IFuture to allow for inspection of the state of the
computation by clients, as well as access to any return values of
IProgressRunnable.run(IProgressMonitor). Will not be
null.java.lang.IllegalThreadStateException