R - the result type of the computation.public class Tasklet<R>
extends java.lang.Object
implements java.lang.Runnable, java.util.function.BiFunction<R,java.lang.Throwable,R>
A Tasklet wraps a user-provided Callable and manages its execution context.
Unlike standard FutureTask, a Tasklet is designed to:
qid).SecondaryLoop.ProgressDisplayI and parent relationships.For off-EDT tasks, this class uses a specific CompletableFuture pattern.
The result future (returned to the caller) is chained to a trigger future via
CompletableFuture.handleAsync(BiFunction, java.util.concurrent.Executor).
Calling spawn() completes the trigger, which signals the ForkJoinPool to pick up
this Tasklet (via the apply(R, java.lang.Throwable) method) and execute the actual logic.
Tasklet supports async-stacktraces, which are disabled by default due to their impact on performance.
They can be enabled by setting the log-level of this class to DEBUG, either by its client-log.conf or programmatically:
org.apache.log4j.Logger.getLogger(de.ipcon.tools.concurrent.Tasklet.class).setLevel(org.apache.log4j.Level.DEBUG)
To log all Throwable thrown by tasks, additionally to completing the task exceptionally, enable Level.TRACE
| Modifier and Type | Class and Description |
|---|---|
static class |
Tasklet.AsyncThreadException |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Throwable |
appendAsyncThreadCause(java.lang.Throwable cause)
If originThread information is logged, then the stacktraces of the originThread are added as cause to the provided throwable.
|
R |
apply(R input,
java.lang.Throwable exception)
Entry point for off-EDT execution via
CompletableFuture.handleAsync(java.util.function.BiFunction<? super T, java.lang.Throwable, ? extends U>). |
static ProgressDisplayI |
currentProgressDisplay()
Retrieves the
ProgressDisplayI associated with the current task. |
static java.lang.Throwable |
getAsyncThreadCause(java.lang.Throwable cause)
Appends the Cross-Thread information of the currently running tasklet and all its parents
as cause to the given cause.
|
void |
run()
The core execution logic.
|
static void |
setCurrentProgressDisplay(ProgressDisplayI progressDisplay)
Associates a
ProgressDisplayI with the currently running Tasklet. |
java.lang.String |
toString() |
public R apply(R input, java.lang.Throwable exception)
CompletableFuture.handleAsync(java.util.function.BiFunction<? super T, java.lang.Throwable, ? extends U>).
This acts as an adapter between the CompletableFuture API and our run() method.
It waits for the result (which is computed inside run()) to ensure the future chain completes.
public void run()
This method:
result future.run in interface java.lang.Runnablepublic static void setCurrentProgressDisplay(ProgressDisplayI progressDisplay)
ProgressDisplayI with the currently running Tasklet.
This allows progress updates to be routed to the correct UI component associated with this task.progressDisplay - the progress display to set.public static java.lang.Throwable getAsyncThreadCause(java.lang.Throwable cause)
cause - a nonnull throwable to append the asynchronous threads as cause.public java.lang.Throwable appendAsyncThreadCause(java.lang.Throwable cause)
cause - the nullable cause to append the information to.public static ProgressDisplayI currentProgressDisplay()
ProgressDisplayI associated with the current task.null.public java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2000-2026 OAshi S.à r.l. All Rights Reserved.