Class AsyncTask
One call of an @Async method, and the Future its caller holds.
The build generates a subclass per @Async method whose fields are the
call's arguments and whose call() invokes the method's original body.
The rewritten method constructs one, hands it to its executor and returns it,
so the caller's Future is this object. A method whose body itself
returns a Future -- AsyncResult.of(V) -- completes this one with that
Future's value.
The caller's span, if it was being traced, is the parent of the span the call runs in, so the background work shows up under the request that started it.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Objectcall()Runs the method's body.booleancancel(boolean mayInterruptIfRunning) Cancels the call if it has not started.get()Waits for the work to finish and returns its result.Waits up totimeoutfor the work to finish and returns its result.booleanWhetherFuture.cancel(boolean)cancelled the work before it ran.booleanisDone()Whether the work has finished: completed, failed or cancelled.final voidrun()When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.toString()Returns a string representation of the object.
-
Constructor Details
-
AsyncTask
Parameters
-
name: what the span is called: the class and the method -
returnsVoid: @param returnsVoid whether the method returns nothing, so a failure has nobody to be delivered to and is reported instead
-
-
-
Method Details
-
call
-
run
public final void run()Description copied from interface:RunnableWhen an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread. The general contract of the method run is that it may take any action whatsoever. -
cancel
-
isCancelled
public boolean isCancelled()Description copied from interface:FutureWhetherFuture.cancel(boolean)cancelled the work before it ran.- Specified by:
isCancelledin interfaceFuture- Returns:
- true when cancelled
-
isDone
-
get
Description copied from interface:FutureWaits for the work to finish and returns its result.- Specified by:
getin interfaceFuture- Returns:
- the result
- Throws:
InterruptedException- when the waiting thread is interruptedExecutionException- when the work threw;Throwable.getCause()is what it threw
-
get
public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Description copied from interface:FutureWaits up totimeoutfor the work to finish and returns its result.- Specified by:
getin interfaceFuture- Parameters:
timeout- how long to wait, inunitunit- the unit oftimeout- Returns:
- the result
- Throws:
InterruptedException- when the waiting thread is interruptedExecutionException- when the work threwTimeoutException- when it has not finished in time
-
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
-