Class InterruptibleTask<T>
- java.lang.Object
-
- java.util.concurrent.atomic.AtomicReference<java.lang.Runnable>
-
- com.google.common.util.concurrent.InterruptibleTask<T>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Runnable
- Direct Known Subclasses:
CombinedFuture.CombinedFutureInterruptibleTask,TrustedListenableFutureTask.TrustedFutureInterruptibleAsyncTask,TrustedListenableFutureTask.TrustedFutureInterruptibleTask
abstract class InterruptibleTask<T> extends java.util.concurrent.atomic.AtomicReference<java.lang.Runnable> implements java.lang.Runnable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classInterruptibleTask.BlockerUsing 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.private static classInterruptibleTask.DoNothingRunnable
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.RunnableDONEprivate static intMAX_BUSY_WAIT_SPINSprivate static java.lang.RunnablePARKED
-
Constructor Summary
Constructors Constructor Description InterruptibleTask()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract voidafterRanInterruptiblyFailure(java.lang.Throwable error)Any interruption that happens as a result of calling interruptTask will arrive before this method is called.(package private) abstract voidafterRanInterruptiblySuccess(T result)Any interruption that happens as a result of calling interruptTask will arrive before this method is called.(package private) voidinterruptTask()Interrupts the running task.(package private) abstract booleanisDone()Called before runInterruptibly - if true, runInterruptibly and afterRanInterruptibly will not be called.voidrun()(package private) abstract TrunInterruptibly()Do interruptible work here - do not complete Futures here, as their listeners could be interrupted.(package private) abstract java.lang.StringtoPendingString()java.lang.StringtoString()private voidwaitForInterrupt(java.lang.Thread currentThread)-
Methods inherited from class java.util.concurrent.atomic.AtomicReference
accumulateAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, get, getAcquire, getAndAccumulate, getAndSet, getAndUpdate, getOpaque, getPlain, lazySet, set, setOpaque, setPlain, setRelease, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
-
-
-
-
Field Detail
-
DONE
private static final java.lang.Runnable DONE
-
PARKED
private static final java.lang.Runnable PARKED
-
MAX_BUSY_WAIT_SPINS
private static final int MAX_BUSY_WAIT_SPINS
- See Also:
- Constant Field Values
-
-
Method Detail
-
run
public final void run()
- Specified by:
runin interfacejava.lang.Runnable
-
waitForInterrupt
private void waitForInterrupt(java.lang.Thread currentThread)
-
isDone
abstract boolean isDone()
Called before runInterruptibly - if true, runInterruptibly and afterRanInterruptibly will not be called.
-
runInterruptibly
abstract T runInterruptibly() throws java.lang.Exception
Do interruptible work here - do not complete Futures here, as their listeners could be interrupted.- Throws:
java.lang.Exception
-
afterRanInterruptiblySuccess
abstract void afterRanInterruptiblySuccess(T result)
Any interruption that happens as a result of calling interruptTask will arrive before this method is called. Complete Futures here.
-
afterRanInterruptiblyFailure
abstract void afterRanInterruptiblyFailure(java.lang.Throwable error)
Any interruption that happens as a result of calling interruptTask will arrive before this method is called. Complete Futures here.
-
interruptTask
final void interruptTask()
Interrupts the running task. Because this internally callsThread.interrupt()which can in turn invoke arbitrary code it is not safe to call while holding a lock.
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.util.concurrent.atomic.AtomicReference<java.lang.Runnable>
-
toPendingString
abstract java.lang.String toPendingString()
-
-