public class Executor
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
protected IExecutable |
executable
The executable.
|
static java.lang.ThreadLocal<Executor> |
EXECUTOR
The executor belonging to a thread.
|
protected int |
exethreadcnt
The number of current threads for this executor.
|
protected java.lang.Object |
monitor
The monitor to synchronize with at thread start (if any).
|
protected boolean |
running
Flag indicating if the thread is running.
|
protected java.util.List<Future<java.lang.Void>> |
shutdownfutures
The shutdown futures.
|
protected java.util.List<java.lang.Object> |
switchtos
The monitors of blocked threads that need to be reactivated.
|
protected IThreadPool |
threadpool
The thread pool.
|
protected java.util.Map<java.lang.Object,java.lang.Throwable> |
throwables
The exceptions (if any) to be thrown in threads that need to be reactivated.
|
protected boolean |
wanttorun
Flag indicating if the thread wants to run.
|
Constructor and Description |
---|
Executor(IThreadPool threadpool)
Create an executor object.
|
Executor(IThreadPool threadpool,
IExecutable executable)
Create an executor object.
|
Modifier and Type | Method and Description |
---|---|
void |
blockThread(java.lang.Object monitor)
Adjust to execution of current thread to be blocked.
|
protected boolean |
code()
The code to be run.
|
boolean |
execute()
Make sure a thread is executing the code.
|
protected int |
getThreadCount()
Get the number of threads (running blocked)
for this executor.
|
protected boolean |
isRunning()
Check if the executor is running.
|
boolean |
isSwitching()
Check if the executor wants to switch threads.
|
void |
run()
Execute the code.
|
void |
setExecutable(IExecutable executable)
Set the executable.
|
IFuture<java.lang.Void> |
shutdown()
Shutdown the executor.
|
void |
switchThread(java.lang.Object monitor,
java.lang.Throwable t)
Cease execution of the current thread and
switch to another thread waiting for the given monitor.
|
java.lang.String |
toString()
String representation.
|
public static final java.lang.ThreadLocal<Executor> EXECUTOR
protected boolean running
protected boolean wanttorun
protected IThreadPool threadpool
protected IExecutable executable
protected java.util.List<Future<java.lang.Void>> shutdownfutures
protected java.lang.Object monitor
protected int exethreadcnt
protected java.util.List<java.lang.Object> switchtos
protected java.util.Map<java.lang.Object,java.lang.Throwable> throwables
public Executor(IThreadPool threadpool)
public Executor(IThreadPool threadpool, IExecutable executable)
public void run()
run
in interface java.lang.Runnable
public boolean execute()
public IFuture<java.lang.Void> shutdown()
public void setExecutable(IExecutable executable)
executable
- The executable.protected boolean code()
protected boolean isRunning()
protected int getThreadCount()
public void switchThread(java.lang.Object monitor, java.lang.Throwable t)
monitor
- The monitor to be notified.t
- The exception to be thrown on the unblocked thread (null for continuing normal execution).public void blockThread(java.lang.Object monitor)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isSwitching()