public class WorkerThread extends Thread
Runnable
instances from a
queue and executes them. This class is intended to be used with a Semaphore
, whereby work is added the to the
queue and the semaphore indicates when processing has finished.Thread.State, Thread.UncaughtExceptionHandler
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
WorkerThread(BlockingQueue<Runnable> workQueue)
Creates a thread that continuously dequeues from the
workQueue at
once and excutes each item. |
WorkerThread(BlockingQueue<Runnable> workQueue,
int threadLocalItems)
Creates a thread that continuously dequeues
threadLocalItems from
workQueue at once and excutes them sequentially. |
Modifier and Type | Method and Description |
---|---|
void |
run()
Continuously dequeues
Runnable instances from the work queue and
execute them. |
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
public WorkerThread(BlockingQueue<Runnable> workQueue)
workQueue
at
once and excutes each item.public WorkerThread(BlockingQueue<Runnable> workQueue, int threadLocalItems)
threadLocalItems
from
workQueue
at once and excutes them sequentially.threadLocalItems
- the number of items this thread should dequeue
from the work queue at one time. Setting this value too high can
result in a loss of concurrency; setting it too low can result in
high contention on the work queue if the time per task is also
low.Copyright © 2012. All Rights Reserved.