|
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 - plus it has additional functionality that the standard JDK implementation has not. Since the JDK 1.5 FCS, this implementation is adopted to implement Executor.
ThreadPool| 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 | |
|---|---|
ThreadWorker.Listener |
addExceptionHandler(Thread.UncaughtExceptionHandler handler)
|
boolean |
addListener(ThreadWorker.Listener listener)
|
static Runnable |
asRunnable(Task<?> task)
|
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 already been executed |
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 |
isReady()
if ready, this instance will accept new tasks |
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. |
int |
runTask(Task<?> task)
|
void |
waitFor(Runnable myTask)
waits until the given task has been executed on this Executor |
void |
waitForActiveQueue()
waits until all currently scheduled tasks have been executed |
boolean |
willEndAfterCurrent()
|
boolean |
willEndAfterLast()
|
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, clone, 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 |
|---|
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 ThreadWorker.Listener addExceptionHandler(Thread.UncaughtExceptionHandler handler)
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 int runTask(Task<?> task)
throws IllegalStateException
IllegalStateExceptionrunTask(Runnable)public static Runnable asRunnable(Task<?> task)
public void run()
throws IllegalThreadStateException
start()
run in interface Runnablerun in class ThreadIllegalThreadStateException - if the method is called through
anything but start() oncepublic void waitForActiveQueue()
public void waitFor(Runnable myTask)
public boolean isReady()
public 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 | |||||||||