Package com.google.common.util.concurrent
@ParametersAreNonnullByDefault
package com.google.common.util.concurrent
Concurrency utilities.
Commonly used types include ClosingFuture
, ListenableFuture
, and Service
.
Commonly used utilities include Futures
, MoreExecutors
, ThreadFactoryBuilder
, and Uninterruptibles
.
This package is a part of the open-source Guava library.
-
ClassDescriptionAbstractCatchingFuture<V,
X extends Throwable, F, T> Implementations ofFutures.catching*
.AbstractCatchingFuture.AsyncCatchingFuture<V,X extends Throwable> AnAbstractCatchingFuture
that delegates to anAsyncFunction
andAbstractFuture.setFuture(ListenableFuture)
.AbstractCatchingFuture.CatchingFuture<V,X extends Throwable> Base class for services that can implementAbstractExecutionThreadService.startUp()
,AbstractExecutionThreadService.run()
andAbstractExecutionThreadService.shutDown()
methods.An abstract implementation ofListenableFuture
, intended for advanced users only.A special value to represent cancellation and the 'wasInterrupted' bit.A special value to represent failure, whenAbstractFuture.setException(java.lang.Throwable)
is called successfully.Listeners also form a stack through theAbstractFuture.listeners
field.A special value that encodes the 'setFuture' state.AbstractFuture.AtomicHelper
based onsynchronized
and volatile writes.Tag interface marking trusted subclasses.A less abstract subclass of AbstractFuture.AbstractFuture.AtomicHelper
based onUnsafe
.Waiter links form a Treiber stack, in theAbstractFuture.waiters
field.Base class for services that do not need a thread while "running" but may need one during startup and shutdown.AbstractListeningExecutorService
implementation that createsListenableFuture
instances for eachRunnable
andCallable
submitted to it.Base class for services that can implementAbstractScheduledService.startUp()
andAbstractScheduledService.shutDown()
but while in the "running" state need to perform a periodic task.AAbstractScheduledService.Scheduler
that provides a convenient way for theAbstractScheduledService
to use a dynamically changing schedule.A value object that represents an absolute delay until a task should be invoked.Contains the most recently submittedFuture
, which may be cancelled or updated, always under a lock.A scheduler defines the policy for how theAbstractScheduledService
should run its task.Base class for implementing services that can handleAbstractService.doStart()
andAbstractService.doStop()
requests, responding to them withAbstractService.notifyStarted()
andAbstractService.notifyStopped()
callbacks.An immutable snapshot of the current state of the service.AbstractTransformFuture<I,O, F, T> Implementations ofFutures.transform*
.AnAbstractTransformFuture
that delegates to anAsyncFunction
andAbstractFuture.setFuture(ListenableFuture)
.AggregateFuture<InputT,OutputT> A future whose value is derived from a collection of input futures.AggregateFutureState<OutputT>A helper which does some thread-safe operations for aggregate futures, which must be implemented differently in GWT.Computes a value, possibly asynchronously.AsyncFunction<I,O> Transforms a value, possibly asynchronously.Adouble
value that may be updated atomically.Adouble
array in which elements may be updated atomically.A map containinglong
values that can be atomically updated.Static utility methods pertaining to classes in thejava.util.concurrent.atomic
package.Static utility methods pertaining to theCallable
interface.A step in a pipeline of an asynchronous computation.An operation that computes aClosingFuture
of a result.A function from an input to aClosingFuture
of a result.An operation that computes a result.A function from an input to a result.A builder of aClosingFuture
step that is derived from more than one input step.An operation that returns aClosingFuture
result and may throw an exception.An operation that returns a result and may throw an exception.ClosingFuture.Combiner2<V1,V2> A genericClosingFuture.Combiner
that lets you use a lambda or method reference to combine twoClosingFuture
s.A function that returns aClosingFuture
when applied to the values of the two futures passed toClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture)
.A function that returns a value when applied to the values of the two futures passed toClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture)
.ClosingFuture.Combiner3<V1,V2, V3> A genericClosingFuture.Combiner
that lets you use a lambda or method reference to combine threeClosingFuture
s.ClosingFuture.Combiner3.AsyncClosingFunction3<V1,V2, V3, U> A function that returns aClosingFuture
when applied to the values of the three futures passed toClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture, ClosingFuture)
.ClosingFuture.Combiner3.ClosingFunction3<V1,V2, V3, U> A function that returns a value when applied to the values of the three futures passed toClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture, ClosingFuture)
.ClosingFuture.Combiner4<V1,V2, V3, V4> A genericClosingFuture.Combiner
that lets you use a lambda or method reference to combine fourClosingFuture
s.ClosingFuture.Combiner4.AsyncClosingFunction4<V1,V2, V3, V4, U> A function that returns aClosingFuture
when applied to the values of the four futures passed toClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture, ClosingFuture, ClosingFuture)
.ClosingFuture.Combiner4.ClosingFunction4<V1,V2, V3, V4, U> A function that returns a value when applied to the values of the four futures passed toClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture, ClosingFuture, ClosingFuture)
.ClosingFuture.Combiner5<V1,V2, V3, V4, V5> A genericClosingFuture.Combiner
that lets you use a lambda or method reference to combine fiveClosingFuture
s.ClosingFuture.Combiner5.AsyncClosingFunction5<V1,V2, V3, V4, V5, U> A function that returns aClosingFuture
when applied to the values of the five futures passed toClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture, ClosingFuture, ClosingFuture, ClosingFuture)
.ClosingFuture.Combiner5.ClosingFunction5<V1,V2, V3, V4, V5, U> A function that returns a value when applied to the values of the five futures passed toClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture, ClosingFuture, ClosingFuture, ClosingFuture)
.An object that can capture objects to be closed later, when aClosingFuture
pipeline is done.An object that can return the value of theClosingFuture
s that are passed toClosingFuture.whenAllComplete(Iterable)
orClosingFuture.whenAllSucceed(Iterable)
.The state of aClosingFuture.CloseableList
.An object that holds the final result of an asynchronousClosingFuture
operation and allows the user to close all the closeable objects that were captured during it for later closing.Represents an operation that accepts aClosingFuture.ValueAndCloser
for the last step in aClosingFuture
pipeline.CollectionFuture<V,C> Aggregate future that collects (stores) results of each future.The result of a successfulFuture
.Aggregate future that computes its value by calling a callable.TheCycleDetectingLockFactory
createsReentrantLock
instances andReentrantReadWriteLock
instances that detect potential deadlock by checking for cycles in lock acquisition order.Internal Lock implementations implement theCycleDetectingLock
interface, allowing the detection logic to treat all locks in the same manner.A Throwable used to record a stack trace that illustrates an example of a specific lock acquisition ordering.ALockGraphNode
associated with each lock instance keeps track of the directed edges in the lock acquisition graph.Pre-definedCycleDetectingLockFactory.Policy
implementations.Encapsulates the action to be taken when a potential deadlock is encountered.Represents a detected cycle in lock acquisition ordering.CycleDetectingLockFactory.WithExplicitOrdering<E extends Enum<E>>ACycleDetectingLockFactory.WithExplicitOrdering
provides the additional enforcement of an application-specified ordering of lock acquisitions.See newDirectExecutorService javadoc for behavioral notes.Marks all "top-level" types as non-null in a way that is recognized by Kotlin.Error
variant ofExecutionException
.A support class forListenableFuture
implementations to manage their listeners.Serializes execution of tasks, somewhat like an "asynchronoussynchronized
block." Each enqueued callable will not be submitted to its associated executor until the previous callable has returned -- and, if the previous callable was anAsyncCallable
, not until theFuture
it returned isinvalid reference
done
This class helps avoid a StackOverflowError when large numbers of tasks are submitted withMoreExecutors.directExecutor()
.This object is unsafely published, but avoids problematic races by relying exclusively on the identity equality of its Thread field so that the task field is only accessed by a single thread.A TimeLimiter implementation which actually does not attempt to limit time at all.FluentFuture<V>AListenableFuture
that supports fluent chains of operations.A less abstract subclass of AbstractFuture.ABlockingDeque
which forwards all its method calls to anotherBlockingDeque
.ABlockingQueue
which forwards all its method calls to anotherBlockingQueue
.Forwarding wrapper around aCondition
.An executor service which forwards all its method calls to another executor service.FluentFuture
that forwards all calls to a delegate.AFuture
which forwards all its method calls to another future.A simplified version ofForwardingFuture
where subclasses can pass in an already constructedFuture
as the delegate.AListenableFuture
which forwards all its method calls to another future.A simplified version ofForwardingListenableFuture
where subclasses can pass in an already constructedListenableFuture
as the delegate.A listening executor service which forwards all its method calls to another listening executor service.Forwarding wrapper around aLock
.A callback for accepting the results of aFuture
computation asynchronously.Static utility methods pertaining to theFuture
interface.SeeFutures.addCallback(ListenableFuture, FutureCallback, Executor)
for behavioral notes.A helper to create a newListenableFuture
whose result is generated from a combination of input futures.A wrapped future that does not propagate cancellation to its delegate.Static methods used to implementFutures.getChecked(Future, Class)
.Provides a check of whether an exception type is valid for use withFuturesGetChecked.getChecked(Future, Class)
, possibly using caching.Hidden superclass ofFluentFuture
that provides us a place to declare special GWT versions of theinvalid reference
FluentFuture.catching
Hidden superclass ofFutures
that provides us a place to declare special GWT versions of theFutures.catching
family of methods.Implementation ofFutures.immediateFuture(V)
.This class is forcom.google.common.util.concurrent
use only!Using this as the blocker object allows introspection and debugging tools to see that the currentRunner thread is blocked on the progress of the interruptor thread, which can help identify deadlocks.Utilities necessary for working with libraries that supply plainFuture
instances.An adapter to turn aFuture
into aListenableFuture
.A holder for aLogger
that is initialized only when requested.AFuture
that accepts completion listeners.AFutureTask
that also implements theListenableFuture
interface.Helper interface to implement bothListenableFuture
andScheduledFuture
.A list of listeners for implementing a concurrency friendly observable object.Method reference-compatible listener event.A special purpose queue/executor that dispatches listener events serially on a configured executor.AnExecutorService
that returnsListenableFuture
instances.AScheduledExecutorService
that returnsListenableFuture
instances from itsExecutorService
methods.A synchronization abstraction supporting waiting on arbitrary boolean conditions.A boolean condition for which a thread may wait.Represents the current application to register shutdown hooks.A utility method to perform unchecked casts to suppress errors produced by nullness analyses.Works around an android bug, where parking for more than INT_MAX seconds can produce an abort signal on 32 bit devices running Android Q.Annotates a "top-level" type-variable usage that takes its nullness from the type argument supplied by the user of the class.Outer class that exists solely to let us writePartially.GwtIncompatible
instead of plainGwtIncompatible
.The presence of this annotation on an API indicates that the method may be used with the Google Web Toolkit (GWT) but that it has some restrictions.Methods factored out so that they can be emulated differently in GWT.A rate limiter.Static utility methods pertaining to theRunnable
interface.Executor ensuring that all Runnables submitted are executed in order, using the provided Executor, and sequentially such that no two will ever be running at the same time.An object with an operational state, plus asynchronousService.startAsync()
andService.stopAsync()
lifecycle methods to transition between states.A listener for the various state changes that aService
goes through in its lifecycle.The lifecycle states of a service.A manager for monitoring and controlling a set of services.This is never thrown but only used for logging.A listener for the aggregate state changes of the services that are under management.AService
instance that does nothing.AService
that wraps another service and times how long it takes for it to start and also calls theServiceManager.ServiceManagerState.transitionService(Service, State, State)
, to record the state transitions.An encapsulation of all the mutable state of theServiceManager
that needs to be accessed by instances ofServiceManager.ServiceListener
.Superinterface ofServiceManager
to introduce a bridge method forservicesByState()
, to ensure binary compatibility with older Guava versions that specifiedservicesByState()
to returnImmutableMultimap
.AListenableFuture
whose result can be set by aSettableFuture.set(Object)
,SettableFuture.setException(Throwable)
orSettableFuture.setFuture(ListenableFuture)
call.A TimeLimiter that runs method calls in the background using anExecutorService
.This implements a "bursty" RateLimiter, where storedPermits are translated to zero throttling.This implements the following function where coldInterval = coldFactor * stableInterval.Striped<L>A stripedLock/Semaphore/ReadWriteLock
.Implementation of Striped where 2^k stripes are represented as an array of the same length, eagerly initialized.Implementation of Striped where up to 2^k stripes can be represented, using a ConcurrentMap where the key domain is [0..2^k).Implementation of Striped where up to 2^k stripes can be represented, using an AtomicReferenceArray of size 2^k.Condition object that ensures a strong reference is retained to a specified object.Lock object that ensures a strong reference is retained to a specified object.ReadWriteLock implementation whose read and write locks retain a reference back to this lock.A ThreadFactory builder, providing any combination of these features: whether threads should be marked as daemon threads a naming format a thread priority an uncaught exception handler a backing thread factoryImposes a time limit on method calls.Implementation ofFutures#withTimeout
.A runnable that is called when the delegate or the timer completes.ARunnableFuture
that also implements theListenableFuture
interface.Factories forThread.UncaughtExceptionHandler
instances.Unchecked variant ofExecutionException
.Unchecked version ofTimeoutException
.Utilities for treating interruptible operations as uninterruptible.An abstractExecutorService
that allows subclasses to wrap tasks before they are submitted to the underlying executor.An abstractScheduledExecutorService
that allows subclasses to wrap tasks before they are submitted to the underlying executor.