|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.jabb.util.thread.QueueConsumer<E>
net.sf.jabb.util.thread.QueueProcessor<E>
E - Type of the data in the queue.public abstract class QueueProcessor<E>
A template for processing data one by one from a queue.
一个从队列中逐个取得数据进行处理的模板,数据一个一个被取走并处理。
One working thread will be created for each instance of this class when necessary.
本类的每个实例相应的会有一个工作线程在需要的时候被创建。
| Field Summary |
|---|
| Fields inherited from class net.sf.jabb.util.thread.QueueConsumer |
|---|
defaultThreadPool, mode, MODE_INIT, MODE_RUNNING, MODE_START, MODE_STOP_ASAP, MODE_STOP_WHEN_EMPTY, MODE_STOPPED, name, queue, thread, threadPool |
| Constructor Summary | |
|---|---|
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. 创建一个实例。 |
|
| Method Summary | |
|---|---|
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. 处理一份数据——这个方法应该在子类中被重载。 |
| Methods inherited from class net.sf.jabb.util.thread.QueueConsumer |
|---|
getName, getQueue, preStop, queue, run, setExecutorService, setName, setQueue, start, stop, stop |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
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()
| Method Detail |
|---|
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 processed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||