public class CancellationToken
extends java.lang.Object
CancellationTokenSource
and pass the token returned from
CancellationTokenSource#getToken()
to the asynchronous operation(s).
Call CancellationTokenSource#cancel()
to cancel the operations.
A CancellationToken
can only be cancelled once - it should not be passed to future operations
once cancelled.Modifier and Type | Method and Description |
---|---|
boolean |
isCancellationRequested() |
CancellationTokenRegistration |
register(java.lang.Runnable action)
Registers a runnable that will be called when this CancellationToken is canceled.
|
void |
throwIfCancellationRequested() |
java.lang.String |
toString() |
public boolean isCancellationRequested()
true
if the cancellation was requested from the source, false
otherwise.public CancellationTokenRegistration register(java.lang.Runnable action)
action
- the runnable to be run when the token is cancelled.CancellationTokenRegistration
instance that can be used to unregister
the action.public void throwIfCancellationRequested() throws java.util.concurrent.CancellationException
java.util.concurrent.CancellationException
- if this token has had cancellation requested.
May be used to stop execution of a thread or runnable.public java.lang.String toString()
toString
in class java.lang.Object