ti.pub
Class WorkerThread

java.lang.Object
  extended by java.lang.Thread
      extended by ti.pub.WorkerThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
Node.NonSwingWorker

public class WorkerThread
extends java.lang.Thread

A worker thread is a thread that runs queued runnables, in a FIFO manner.

Version:
0.1
Author:
;Rob Clark;a0873619;San Diego;;

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WorkerThread(int pri)
          Class Constructor.
WorkerThread(int pri, long watchdogTimeout)
          Class Constructor.
WorkerThread(java.lang.String name, int pri, long watchdogTimeout)
          Class Constructor.
 
Method Summary
 void invokeLater(java.lang.Runnable r)
          Enqueue a work unit (a runnable) to be invoked from the context of the worker thread
 void run()
          thread-main
 void run(java.lang.Runnable r)
           
 void runNext(long timeout)
          Run the next work unit (runnable).
 void unhandledException(java.lang.Throwable e)
          Called when unhandled errors occur.
 void watchdogTimeoutExceeded()
          If using the watchdog timer, this is called from some other thread context when the timeout set for executing a runnable has been exceeded.
 
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

WorkerThread

public WorkerThread(int pri)
Class Constructor. Construct a worker thread with the specified priority.

Parameters:
pri - the priority

WorkerThread

public WorkerThread(int pri,
                    long watchdogTimeout)
Class Constructor. Construct a worker thread with the specified priority.

Parameters:
pri - the priority
watchdogTimeout - the watchdog timeout, if a runnable takes longer than this many ms to complete, the watchdogTimeoutExceeded() method will be called from some other thread context. A value of 0 indicates no time limit

WorkerThread

public WorkerThread(java.lang.String name,
                    int pri,
                    long watchdogTimeout)
Class Constructor. Construct a worker thread with the specified priority.

Parameters:
name - the thread name
pri - the priority
watchdogTimeout - the watchdog timeout, if a runnable takes longer than this many ms to complete, the watchdogTimeoutExceeded() method will be called from some other thread context. A value of 0 indicates no time limit
Method Detail

run

public void run()
thread-main

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

run

public void run(java.lang.Runnable r)

unhandledException

public void unhandledException(java.lang.Throwable e)
Called when unhandled errors occur. Can be overriden.


watchdogTimeoutExceeded

public void watchdogTimeoutExceeded()
If using the watchdog timer, this is called from some other thread context when the timeout set for executing a runnable has been exceeded.


runNext

public void runNext(long timeout)
             throws java.lang.InterruptedException
Run the next work unit (runnable). This is normally called repeatedly in a loop by the worker thread, but can be called externally in places where the worker thread may get blocked (ie. showing a modal dialog, etc.).

This should only be called from the context of this worker thread.

Parameters:
timeout - the maximum number of ms to wait for the next work item. A value of 0 indicates to wait forever
Throws:
java.lang.InterruptedException

invokeLater

public void invokeLater(java.lang.Runnable r)
Enqueue a work unit (a runnable) to be invoked from the context of the worker thread

Parameters:
r - the runnable