Package net.sf.jstuff.core.concurrent
Class BlockingExecutorService
java.lang.Object
net.sf.jstuff.core.concurrent.BlockingExecutor
net.sf.jstuff.core.concurrent.BlockingExecutorService
- All Implemented Interfaces:
Executor
,ExecutorService
ExecutorService that blocks submission of new tasks if a given maximum number of tasks are already pending.
- Author:
- Sebastian Thomschke
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final class
Nested classes/interfaces inherited from class net.sf.jstuff.core.concurrent.BlockingExecutor
BlockingExecutor.RunnableWrapper
-
Field Summary
Fields inherited from class net.sf.jstuff.core.concurrent.BlockingExecutor
limiter, maxPendingTasks, maxWaitTime, maxWaitTimeUnit, wrapped
-
Constructor Summary
ConstructorsConstructorDescriptionBlockingExecutorService
(ExecutorService executorService, int maxQueueSize, int maxWaitTime, TimeUnit maxWaitTimeUnit) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
aquirePermits
(int count) boolean
awaitTermination
(long timeout, TimeUnit unit) invokeAll
(Collection<? extends Callable<T>> tasks) invokeAll
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) <T> T
invokeAny
(Collection<? extends Callable<T>> tasks) <T> T
invokeAny
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) boolean
boolean
void
shutdown()
Future<?>
<T> Future<T>
<T> Future<T>
protected <T> Collection<Callable<T>>
wrapTasks
(Collection<? extends Callable<T>> tasks) Methods inherited from class net.sf.jstuff.core.concurrent.BlockingExecutor
aquirePermit, execute, toString
-
Constructor Details
-
BlockingExecutorService
public BlockingExecutorService(ExecutorService executorService, int maxQueueSize, int maxWaitTime, TimeUnit maxWaitTimeUnit) - Parameters:
maxWaitTime
- max time to wait for a tasks being added to the queue
-
-
Method Details
-
aquirePermits
- Throws:
RejectedExecutionException
-
awaitTermination
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException - Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException - Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminated
in interfaceExecutorService
-
shutdown
public void shutdown()- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
- Specified by:
shutdownNow
in interfaceExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
- Throws:
RejectedExecutionException
-
submit
- Specified by:
submit
in interfaceExecutorService
- Throws:
RejectedExecutionException
-
submit
- Specified by:
submit
in interfaceExecutorService
- Throws:
RejectedExecutionException
-
wrapTasks
protected <T> Collection<Callable<T>> wrapTasks(Collection<? extends Callable<T>> tasks) throws RejectedExecutionException - Throws:
RejectedExecutionException
-