E
- Type of the data in the queue.public abstract class QueueProcessor<E> extends QueueConsumer<E>
One working thread will be created for each instance of this class when necessary.
本类的每个实例相应的会有一个工作线程在需要的时候被创建。
defaultThreadPool, mode, MODE_INIT, MODE_RUNNING, MODE_START, MODE_STOP_ASAP, MODE_STOP_WHEN_EMPTY, MODE_STOPPED, name, queue, thread, threadPool
Constructor and Description |
---|
QueueProcessor()
Constructor to create an instance with default name and using default thread pool.
创建一个实例,使用缺省的名称和缺省的线程池。 |
QueueProcessor(BlockingQueue<E> workQueue)
Constructor to create an instance with default name and using default thread pool.
创建一个实例,使用缺省的名称和缺省的线程池。 |
QueueProcessor(BlockingQueue<E> workQueue,
String name)
Constructor to create an instance using default thread pool.
创建一个使用缺省线程池的实例。 |
QueueProcessor(BlockingQueue<E> workQueue,
String name,
ExecutorService executorService)
Constructor to create an instance.
创建一个实例。 |
QueueProcessor(String name)
Constructor to create an instance using default thread pool.
创建一个使用缺省线程池的实例。 |
QueueProcessor(String name,
ExecutorService executorService)
Constructor to create an instance.
创建一个实例。 |
Modifier and Type | Method and Description |
---|---|
protected void |
consume()
This method is overridden over parent class so that one piece of data is taken
from the queue and
process(Object) is invoked.这个方法被重载了,从而队列中的一份数据会被取出并调用 process(Object) 方法。 |
abstract void |
process(E obj)
Process one piece of data - this method should be overridden in subclass.
处理一份数据——这个方法应该在子类中被重载。 |
public QueueProcessor(BlockingQueue<E> workQueue, String name, ExecutorService executorService)
name
- Name of this instance, which determines the naming of working thread.workQueue
- The queue that data for processing will be fetched from.executorService
- Thread pool that working thread will be get from.public QueueProcessor(String name, ExecutorService executorService)
name
- Name of this instance, which determines the naming of working thread.executorService
- Thread pool that working thread will be get from.public QueueProcessor(BlockingQueue<E> workQueue, String name)
name
- Name of this instance, which determines the naming of working thread.workQueue
- The queue that data for processing will be fetched from.public QueueProcessor(String name)
name
- Name of this instance, which determines the naming of working thread.public QueueProcessor(BlockingQueue<E> workQueue)
workQueue
- The queue that data for processing will be fetched from.public QueueProcessor()
protected void consume()
process(Object)
is invoked.process(Object)
方法。consume
in class QueueConsumer<E>
public abstract void process(E obj)
This method may be interrupted while running, so please note the following:
这个方法在运行过程中可能会遇到线程的interrupt,所以如果有以下情况要注意正确处理:
If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.
If this thread is blocked in an I/O operation upon an interruptible channel then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a ClosedByInterruptException.
If this thread is blocked in a Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked.
obj
- The data taken from queue, which needs to be processedCopyright © 2014. All Rights Reserved.