Top Inners Fields Constructors Methods
com.mchange.v3.concurrent

public final Class BoundedExecutorService

extends AbstractExecutorService
Class Inheritance
Imports
java.util.*, java.util.concurrent.AbstractExecutorService, .Callable, .ExecutorService, .FutureTask, .RejectedExecutionException, .RunnableFuture, .TimeUnit, com.mchange.v2.log.MLevel, .MLog, .MLogger

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
private class
private class
private class
pack-priv static enum

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final ExecutorService
pack-priv static final MLogger
pack-priv int
pack-priv final int
pack-priv BoundedExecutorService.State
pack-priv Map<Thread, Runnable>

Constructor Summary

AccessConstructor and Description
public
BoundedExecutorService(ExecutorService inner, int blockBound, int restartBeneath)

public
BoundedExecutorService(ExecutorService inner, int blockBound)

Method Summary

Modifier and TypeMethod and Description
private synchronized void
public synchronized boolean
awaitTermination(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

private void
public void
execute(Runnable
the runnable task
runnable
)

Implements java.util.concurrent.Executor.execute.

Executes the given command at some time in the future.

public synchronized BoundedExecutorService.State
public synchronized boolean
isShutdown()

Implements java.util.concurrent.ExecutorService.isShutdown.

Returns true if this executor has been shut down.

public synchronized boolean
isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down.

protected <V> RunnableFuture<V>
newTaskFor(Callable<V>
the callable task being wrapped
callable
)

Overrides java.util.concurrent.AbstractExecutorService.newTaskFor.

Returns a RunnableFuture for the given callable task.

protected <V> RunnableFuture<V>
newTaskFor(Runnable
the runnable task being wrapped
runnable
,
V
the default value for the returned future
result
)

Overrides java.util.concurrent.AbstractExecutorService.newTaskFor.

Returns a RunnableFuture for the given runnable and default value.

private synchronized void
private boolean
public synchronized void
shutdown()

Implements java.util.concurrent.ExecutorService.shutdown.

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

public synchronized List<Runnable>
shutdownNow()

Implements java.util.concurrent.ExecutorService.shutdownNow.

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

private void
Inherited from java.util.concurrent.AbstractExecutorService:
invokeAllinvokeAllinvokeAnyinvokeAnysubmitsubmitsubmit

Field Detail

blockBoundback to summary
pack-priv final int blockBound
innerback to summary
pack-priv final ExecutorService inner
loggerback to summary
pack-priv static final MLogger logger
permitsback to summary
pack-priv int permits
restartBeneathback to summary
pack-priv final int restartBeneath
stateback to summary
pack-priv BoundedExecutorService.State state
waitersback to summary
pack-priv Map<Thread, Runnable> waiters

Constructor Detail

BoundedExecutorServiceback to summary
public BoundedExecutorService(ExecutorService inner, int blockBound, int restartBeneath)
BoundedExecutorServiceback to summary
public BoundedExecutorService(ExecutorService inner, int blockBound)

Method Detail

acquirePermitback to summary
private synchronized void acquirePermit(Runnable task)
awaitTerminationback to summary
public synchronized boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException

Implements java.util.concurrent.ExecutorService.awaitTermination.

Doc from java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:boolean

true if this executor terminated and false if the timeout elapsed before termination

Exceptions
InterruptedException:
if interrupted while waiting
doUpdateStateback to summary
private void doUpdateState(BoundedExecutorService.State newState)
executeback to summary
public void execute(Runnable runnable)

Implements java.util.concurrent.Executor.execute.

Doc from java.util.concurrent.Executor.execute.

Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.

Parameters
runnable:Runnable

the runnable task

getStateback to summary
public synchronized BoundedExecutorService.State getState()
isShutdownback to summary
public synchronized boolean isShutdown()

Implements java.util.concurrent.ExecutorService.isShutdown.

Doc from java.util.concurrent.ExecutorService.isShutdown.

Returns true if this executor has been shut down.

Returns:boolean

true if this executor has been shut down

isTerminatedback to summary
public synchronized boolean isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Doc from java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.

Returns:boolean

true if all tasks have completed following shut down

newTaskForback to summary
protected <V> RunnableFuture<V> newTaskFor(Callable<V> callable)

Overrides java.util.concurrent.AbstractExecutorService.newTaskFor.

Doc from java.util.concurrent.AbstractExecutorService.newTaskFor.

Returns a RunnableFuture for the given callable task.

Parameters
<V>
the type of the callable's result
callable:Callable<V>

the callable task being wrapped

Returns:RunnableFuture<V>

a RunnableFuture which, when run, will call the underlying callable and which, as a Future, will yield the callable's result as its result and provide for cancellation of the underlying task

newTaskForback to summary
protected <V> RunnableFuture<V> newTaskFor(Runnable runnable, V result)

Overrides java.util.concurrent.AbstractExecutorService.newTaskFor.

Doc from java.util.concurrent.AbstractExecutorService.newTaskFor.

Returns a RunnableFuture for the given runnable and default value.

Parameters
<V>
the type of the given value
runnable:Runnable

the runnable task being wrapped

result:V

the default value for the returned future

Returns:RunnableFuture<V>

a RunnableFuture which, when run, will run the underlying runnable and which, as a Future, will yield the given value as its result and provide for cancellation of the underlying task

releasePermitback to summary
private synchronized void releasePermit()
shouldWaitback to summary
private boolean shouldWait()
shutdownback to summary
public synchronized void shutdown()

Implements java.util.concurrent.ExecutorService.shutdown.

Doc from java.util.concurrent.ExecutorService.shutdown.

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.

This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.

shutdownNowback to summary
public synchronized List<Runnable> shutdownNow()

Implements java.util.concurrent.ExecutorService.shutdownNow.

Doc from java.util.concurrent.ExecutorService.shutdownNow.

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

This method does not wait for actively executing tasks to terminate. Use awaitTermination to do that.

There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread#interrupt, so any task that fails to respond to interrupts may never terminate.

Returns:List<Runnable>

list of tasks that never commenced execution

updateStateback to summary
private void updateState(BoundedExecutorService.State newState)
com.mchange.v3.concurrent back to summary

private Interface BoundedExecutorService.DelayedTaskSettable<V>

Known Direct Implementers
com.mchange.v3.concurrent.BoundedExecutorService.PermitAcquiringCallable, com.mchange.v3.concurrent.BoundedExecutorService.PermitAcquiringRunnable

Method Summary

Modifier and TypeMethod and Description
public void

Method Detail

setTaskback to summary
public void setTask(BoundedExecutorService.ReleasingFutureTask<V> task)
com.mchange.v3.concurrent back to summary

private final Class BoundedExecutorService.PermitAcquiringCallable<V>

extends Object
implements Callable<V>, BoundedExecutorService.DelayedTaskSettable<V>
Class Inheritance
  • java.lang.Object
  • com.mchange.v3.concurrent.BoundedExecutorService.PermitAcquiringCallable
All Implemented Interfaces
com.mchange.v3.concurrent.BoundedExecutorService.DelayedTaskSettable, java.util.concurrent.Callable

Field Summary

Modifier and TypeField and Description
pack-priv Callable<V>
pack-priv BoundedExecutorService.ReleasingFutureTask<V>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public V
call()

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callableback to summary
pack-priv Callable<V> callable
taskback to summary
pack-priv BoundedExecutorService.ReleasingFutureTask<V> task

Constructor Detail

PermitAcquiringCallableback to summary
pack-priv PermitAcquiringCallable(Callable<V> callable)

Method Detail

callback to summary
public V call() throws Exception

Implements java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Returns:V

computed result

Exceptions
Exception:
if unable to compute a result
setTaskback to summary
public void setTask(BoundedExecutorService.ReleasingFutureTask<V> task)

Implements com.mchange.v3.concurrent.BoundedExecutorService.DelayedTaskSettable.setTask.

com.mchange.v3.concurrent back to summary

private final Class BoundedExecutorService.PermitAcquiringRunnable<V>

extends Object
implements Runnable, BoundedExecutorService.DelayedTaskSettable<V>
Class Inheritance
  • java.lang.Object
  • com.mchange.v3.concurrent.BoundedExecutorService.PermitAcquiringRunnable
All Implemented Interfaces
com.mchange.v3.concurrent.BoundedExecutorService.DelayedTaskSettable, java.lang.Runnable

Field Summary

Modifier and TypeField and Description
pack-priv Runnable
pack-priv BoundedExecutorService.ReleasingFutureTask<V>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

runnableback to summary
pack-priv Runnable runnable
taskback to summary
pack-priv BoundedExecutorService.ReleasingFutureTask<V> task

Constructor Detail

PermitAcquiringRunnableback to summary
pack-priv PermitAcquiringRunnable(Runnable runnable)

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

setTaskback to summary
public void setTask(BoundedExecutorService.ReleasingFutureTask<V> task)

Implements com.mchange.v3.concurrent.BoundedExecutorService.DelayedTaskSettable.setTask.

com.mchange.v3.concurrent back to summary

private final Class BoundedExecutorService.ReleasingFutureTask<V>

extends FutureTask<V>
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
done()

Overrides java.util.concurrent.FutureTask.done.

Protected method invoked when this task transitions to state isDone (whether normally or via cancellation).

Inherited from java.util.concurrent.FutureTask:
cancelexceptionNowgetgetisCancelledisDoneresultNowrunrunAndResetsetsetExceptionstatetoString

Constructor Detail

ReleasingFutureTaskback to summary
pack-priv ReleasingFutureTask(BoundedExecutorService.PermitAcquiringCallable<V> callable)
ReleasingFutureTaskback to summary
pack-priv ReleasingFutureTask(BoundedExecutorService.PermitAcquiringRunnable<V> runnable, V result)

Method Detail

doneback to summary
protected void done()

Overrides java.util.concurrent.FutureTask.done.

Doc from java.util.concurrent.FutureTask.done.

Protected method invoked when this task transitions to state isDone (whether normally or via cancellation). The default implementation does nothing. Subclasses may override this method to invoke completion callbacks or perform bookkeeping. Note that you can query status inside the implementation of this method to determine whether this task has been cancelled.

com.mchange.v3.concurrent back to summary

pack-priv final Enum BoundedExecutorService.State

extends Enum<BoundedExecutorService.State>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final BoundedExecutorService.State
public static final BoundedExecutorService.State
public static final BoundedExecutorService.State
public static final BoundedExecutorService.State
public static final BoundedExecutorService.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static BoundedExecutorService.State
public static BoundedExecutorService.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ACCEPTINGback to summary
public static final BoundedExecutorService.State ACCEPTING
SATURATEDback to summary
public static final BoundedExecutorService.State SATURATED
SHUTDOWNback to summary
public static final BoundedExecutorService.State SHUTDOWN
SHUTDOWN_NOWback to summary
public static final BoundedExecutorService.State SHUTDOWN_NOW
UNWINDINGback to summary
public static final BoundedExecutorService.State UNWINDING

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static BoundedExecutorService.State valueOf(String name)
valuesback to summary
public static BoundedExecutorService.State[] values()