|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
com.antelmann.util.ThreadWorker
public class ThreadWorker
ThreadWorker runs tasks in a separate thread, where the tasks are queued up and performed one by one. Java 1.5 makes this class somewhat obsolete, but it's still there as it has been used elsewhere in this framework. Since the JDK 1.5 FCS, this implementation is adopted to implement Executor.
| Nested Class Summary | |
|---|---|
static interface |
ThreadWorker.Listener
listens for tasks run by a ThreadWorker to be finished |
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary |
|---|
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
ThreadWorker()
|
|
ThreadWorker(String name)
|
|
ThreadWorker(ThreadGroup group,
String name)
|
|
| Method Summary | |
|---|---|
boolean |
addListener(ThreadWorker.Listener listener)
|
void |
endAfterCurrent()
ends the thread after the current task ended; the effect is irreversible |
void |
endAfterLast()
ends the thread after the last queued task ended; the effect is irreversible |
void |
execute(Runnable task)
calls runTask(task); this method enables usability with jdk1.5 |
Runnable |
getCurrentTask()
returns the Runnable object currently executed by this ThreadWorker |
long |
getCurrentTaskRunningTime()
if no task is currently running, -1 is returned. |
ThreadWorker.Listener[] |
getListeners()
|
int |
getQueueSize()
returns the number of Runnable objects waiting to be executed |
int |
getTaskCount()
returns the number of tasks that have been executed (including the current one) |
Runnable[] |
getTasks()
returns all tasks currently in the queue (including the current one) |
long |
getTotalRunningTime()
excludes time where this thread is waiting for requests |
boolean |
isIdle()
|
boolean |
removeListener(ThreadWorker.Listener listener)
|
boolean |
removeTask(Runnable task)
|
void |
run()
should be called only once through start() |
int |
runTask(Runnable task)
runs the given task immediately after all previous tasks have finished - once the ThreadWorker has been started. |
boolean |
willEndAfterCurrent()
|
boolean |
willEndAfterLast()
|
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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 |
| Constructor Detail |
|---|
public ThreadWorker()
public ThreadWorker(String name)
public ThreadWorker(ThreadGroup group,
String name)
| Method Detail |
|---|
public boolean addListener(ThreadWorker.Listener listener)
public boolean removeListener(ThreadWorker.Listener listener)
public ThreadWorker.Listener[] getListeners()
public Runnable getCurrentTask()
public int getQueueSize()
public boolean isIdle()
public Runnable[] getTasks()
public boolean removeTask(Runnable task)
throws IllegalStateException
IllegalStateException - if the given task is currently runningpublic int getTaskCount()
public long getTotalRunningTime()
public long getCurrentTaskRunningTime()
public void execute(Runnable task)
runTask(task); this method enables usability with jdk1.5
execute in interface Executor
public int runTask(Runnable task)
throws IllegalStateException
IllegalStateException - if the task has no chance anymore of being run
public void run()
throws IllegalThreadStateException
start()
run in interface Runnablerun in class ThreadIllegalThreadStateException - if the method is called through
anything but start() oncepublic void endAfterLast()
public void endAfterCurrent()
public boolean willEndAfterCurrent()
public boolean willEndAfterLast()
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||