|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--com.ls.util.threading.ThreadPoolWorker
Alternative implementation of a thread pool worker. Uses better synchronisation mechanisms to provide a secure and efficient contol over the worker thread.
Field Summary | |
static byte |
STATE_BUSY
Indicates that the thread is processing a task |
static byte |
STATE_IDLE
Indicates, that the thread is running, but has nothing to do |
static byte |
STATE_STOP
Indicates, that the thread is stopped (not running). |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
ThreadPoolWorker(ThreadPool threadPool,
String name)
Constructs a new pool worker. |
Method Summary | |
void |
interrupt()
Interrupts the currently executing task as well as the whole thread. |
void |
interruptTask()
Interrupts the currently executing task. |
void |
joinTask()
Waits until the currently executing task is finished. |
void |
joinTask(long timeout)
Waits until the currently executing task is finished or the given timout period has passed (in the latter case a TimeoutException is raised). |
void |
run()
The main loop of the worker thread. |
void |
runTask(Runnable task)
Executes the given 'task' argument as soon as possible. |
void |
runTask(Runnable task,
long timeout)
Executes the given 'task' argument as soon as possible. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final byte STATE_STOP
public static final byte STATE_IDLE
public static final byte STATE_BUSY
Constructor Detail |
public ThreadPoolWorker(ThreadPool threadPool, String name)
threadPool
- The thread pool object to which this new worker thread belongs.name
- The name of the worker thread.Method Detail |
public void runTask(Runnable task) throws InterruptedException, NotRunningException
task
- The task that should be executed by this worker thread.InterruptedException
- If the caller thread gets interrupted while waiting.NotRunningException
- If the thread is not running, either before start or after termination of the
thread.public void runTask(Runnable task, long timeout) throws InterruptedException, NotRunningException, TimeoutException
TimeoutException
is raised.This method returns immeditately after the thread becomes ready. It will not block until the end of task execution.
task
- The task that should be executed by this worker thread.timeout
- The timeout period (in milliseconds).InterruptedException
- If the caller thread gets interrupted while waiting.NotRunningException
- If the thread is not running, either before start or after termination of the
thread.TimeoutException
- If the given timeout period passes and the thread is still not ready.public void interruptTask()
public void interrupt()
interrupt
in class Thread
public void joinTask() throws InterruptedException
InterruptedException
- If the caller thread gets interrupted while waiting.public void joinTask(long timeout) throws InterruptedException, TimeoutException
TimeoutException
is raised). If there is no executing task this method returns immediately.timeout
- timeout to waitInterruptedException
- If the caller thread gets interrupted while waiting.TimeoutException
- If the given timeout period passes and the thread is still not ready.public void run()
runTask(Runnable)
or runTask(Runnable, long)
and executes them. It calls some callback
methods defined in ThreadPool
to notify about state transitions and task results, and so on.run
in class Thread
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |