V
- public class BufferedThreadPoolExecutorCompletionService<V> extends ExecutorCompletionService<V>
ExecutorCompletionService
which takes a ThreadPoolExecutor
and uses its thread pool to execute tasks - buffering any tasks that
overflow. Such buffered tasks are later re-submitted to the executor when
finished tasks are polled or taken.
This class overrides the ThreadPoolExecutor
's
RejectedExecutionHandler
to collect overflowing tasks. When
poll(long, TimeUnit)
is invoked, this class will attempt to
re-submit any overflow tasks before waiting the specified amount of time.
This will prevent blocking on an empty completion queue since the parent
ExecutorCompletionService
doesn't have any idea that there are tasks
waiting to be resubmitted.
The ScalingThreadPoolExecutor
can be used in conjunction with this
class to provide an efficient buffered, scaling thread pool implementation.Constructor and Description |
---|
BufferedThreadPoolExecutorCompletionService(ThreadPoolExecutor executor) |
Modifier and Type | Method and Description |
---|---|
Future<V> |
poll() |
Future<V> |
poll(long timeout,
TimeUnit unit)
The goal of this method is to prevent blocking if there are tasks waiting
in the overflow queue.
|
Future<V> |
take() |
submit, submit
public BufferedThreadPoolExecutorCompletionService(ThreadPoolExecutor executor)
public Future<V> take() throws InterruptedException
take
in interface CompletionService<V>
take
in class ExecutorCompletionService<V>
InterruptedException
public Future<V> poll()
poll
in interface CompletionService<V>
poll
in class ExecutorCompletionService<V>
public Future<V> poll(long timeout, TimeUnit unit) throws InterruptedException
ExecutorCompletionService.poll(long, TimeUnit)
method. Instead, we
should ensure that we have submitted at least one of our own tasks for
completion.poll
in interface CompletionService<V>
poll
in class ExecutorCompletionService<V>
InterruptedException
Copyright © 2022 Apache Software Foundation. All rights reserved.