-
final class AsyncQueueHandler<T>Asynchronously reads items from provided queue on separate thread borrowed from executor and process items with specified handler. Thread is not blocked when queue is empty and returned back to executor pool. New or existing thread is borrowed from executor when queue is non empty and reader is not running
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description interfaceAsyncQueueHandler.HandlerA simple interface to handle enqueued T items.
-
Constructor Summary
Constructors Constructor Description AsyncQueueHandler(BlockingQueue<T> queue, AsyncQueueHandler.Handler<T> handler, String id, ExecutorService executor)Constructs instance of AsyncQueueHandler which is capable of asynchronous reading provided queue from thread borrowed from executor to process items with provided handler. AsyncQueueHandler(BlockingQueue<T> queue, AsyncQueueHandler.Handler<T> handler, String id, ExecutorService executor, long maxSequentiallyHandledItems)Constructs instance of AsyncQueueHandler which is capable of asynchronous reading provided queue from thread borrowed from executor to process items with provided handler.
-
Method Summary
Modifier and Type Method Description voidcancel()Attempts to stop execution of reader if running voidhandleQueueItemsUntilEmpty()Checks if reader is running on one of executor thread and if no submits execution of reader on executor. -
-
Constructor Detail
-
AsyncQueueHandler
AsyncQueueHandler(BlockingQueue<T> queue, AsyncQueueHandler.Handler<T> handler, String id, ExecutorService executor)
Constructs instance of AsyncQueueHandler which is capable of asynchronous reading provided queue from thread borrowed from executor to process items with provided handler.- Parameters:
queue- thread-safe queue which holds items to processhandler- an implementation of handler routine which will beinvoked per each item placed in the queue.id- optional identifier of current handler for debug purposeexecutor- optional executor service to borrow threads from
-
AsyncQueueHandler
AsyncQueueHandler(BlockingQueue<T> queue, AsyncQueueHandler.Handler<T> handler, String id, ExecutorService executor, long maxSequentiallyHandledItems)
Constructs instance of AsyncQueueHandler which is capable of asynchronous reading provided queue from thread borrowed from executor to process items with provided handler.- Parameters:
queue- thread-safe queue which holds items to processhandler- an implementation of handler routine which will beinvoked per each item placed in the queue.id- optional identifier of current handler for debug purposeexecutor- optional executor service to borrow threads frommaxSequentiallyHandledItems- maximum number of items sequentiallyhandled on thread borrowed from before temporaryreleasing thread and re-acquiring it from .
-
-
Method Detail
-
cancel
void cancel()
Attempts to stop execution of reader if running
-
handleQueueItemsUntilEmpty
void handleQueueItemsUntilEmpty()
Checks if reader is running on one of executor thread and if no submits execution of reader on executor.
-
-
-
-