Verified Owner
Top Description Fields Constructors Methods
org.jabref.gui.util

public Class UiTaskExecutor

extends Object
implements TaskExecutor
Class Inheritance
Imports
java.util.WeakHashMap, java.util.concurrent.Callable, .CountDownLatch, .ExecutionException, .ExecutorService, .Executors, .Future, .FutureTask, .ScheduledExecutorService, .TimeUnit, java.util.function.Consumer, javafx.application.Platform, javafx.concurrent.Task, org.jabref.gui.StateManager, org.jabref.logic.util.BackgroundTask, .DelayTaskThrottler, .TaskExecutor, com.airhacks.afterburner.injection.Injector, org.jspecify.annotations.NonNull, org.slf4j.Logger, .LoggerFactory

A very simple implementation of the TaskExecutor interface. Every submitted task is invoked in a separate thread.

In case something does not interact well with JavaFX, you can use the org.jabref.logic.util.HeadlessExecutorService

Field Summary

Modifier and TypeField and Description
private final ExecutorService
private static final Logger
private final ScheduledExecutorService
private final WeakHashMap<DelayTaskThrottler, Void>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static Exception
public DelayTaskThrottler
createThrottler(int delay)

public <
The background task type
V
>
Future<V>

Returns:

Future of a JavaFX Task which will execute the call method a background thread
execute
(org.jabref.logic.util.BackgroundTask<V>
the BackgroundTask to run
task
)

This will convert the given BackgroundTask to a JavaFX Task The JavaFX task executes the call method a background thread and the onFailed onSucceed on the FX UI thread

public <
type of return value of the task
V
>
Future<V>
execute(Task<V>
the task to run
task
)

Runs the given task and returns a Future representing that task.

public static <V> Task<V>

Returns:

a new Javafx Task object
getJavaFXTask
(org.jabref.logic.util.BackgroundTask<V>
the BackgroundTask to wrap
task
)

Generates a wrapper with a JavaFX Task for our BackgroundTask monitoring the progress based on the data given from the task.

public static void
runAndWaitInJavaFXThread(@NonNull Runnable
the Runnable to run
action
)

Runs the specified Runnable on the JavaFX application thread and waits for completion.

public static void
runAndWaitInJavaFXThreadWithFailurePropagation(@NonNull Runnable
the Runnable to run
action
)

Runs the specified Runnable on the JavaFX application thread and waits for completion.

public static <V> V
public static void
runInJavaFXThread(Runnable
runnable BackgroundTask to run
runnable
)

Runs the runnable later.

public static void
runNowOrInJavaFXThread(Runnable
runnable BackgroundTask to run
runnable
)

Runs the runnable now, when we are already on the FX UI Thread, or later if we are not.

public <V> Future<?>
schedule(org.jabref.logic.util.BackgroundTask<V> task, long delay, TimeUnit unit)

public void
shutdown()

Shuts everything down.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

executorback to summary
private final ExecutorService executor
LOGGERback to summary
private static final Logger LOGGER
scheduledExecutorback to summary
private final ScheduledExecutorService scheduledExecutor
throttlersback to summary
private final WeakHashMap<DelayTaskThrottler, Void> throttlers

Constructor Detail

UiTaskExecutorback to summary
public UiTaskExecutor()

Method Detail

convertToExceptionback to summary
private static Exception convertToException(Throwable throwable)
createThrottlerback to summary
public DelayTaskThrottler createThrottler(int delay)
Annotations
@Override
executeback to summary
public <V> Future<V> execute(org.jabref.logic.util.BackgroundTask<V> task)

This will convert the given BackgroundTask to a JavaFX Task The JavaFX task executes the call method a background thread and the onFailed onSucceed on the FX UI thread

Parameters
<V>
The background task type
task:org.jabref.logic.util.BackgroundTask<V>

the BackgroundTask to run

Returns:Future<V>

Future of a JavaFX Task which will execute the call method a background thread

Annotations
@Override
executeback to summary
public <V> Future<V> execute(Task<V> task)

Runs the given task and returns a Future representing that task. Usually, you want to use the other method execute(BackgroundTask).

Parameters
<V>
type of return value of the task
task:Task<V>

the task to run

getJavaFXTaskback to summary
public static <V> Task<V> getJavaFXTask(org.jabref.logic.util.BackgroundTask<V> task)

Generates a wrapper with a JavaFX Task for our BackgroundTask monitoring the progress based on the data given from the task. call is routed to the given task object.

Parameters
task:org.jabref.logic.util.BackgroundTask<V>

the BackgroundTask to wrap

Returns:Task<V>

a new Javafx Task object

runAndWaitInJavaFXThreadback to summary
public static void runAndWaitInJavaFXThread(@NonNull Runnable action)

Runs the specified Runnable on the JavaFX application thread and waits for completion.

Parameters
action:@NonNull Runnable

the Runnable to run

Exceptions
NullPointerException:
if action is null
runAndWaitInJavaFXThreadWithFailurePropagationback to summary
public static void runAndWaitInJavaFXThreadWithFailurePropagation(@NonNull Runnable action) throws ExecutionException

Runs the specified Runnable on the JavaFX application thread and waits for completion.

Unlike runAndWaitInJavaFXThread(Runnable), this method propagates an exception raised by the action to the waiting thread.

Parameters
action:@NonNull Runnable

the Runnable to run

Exceptions
ExecutionException:
if the action fails
runInJavaFXThreadback to summary
public static <V> V runInJavaFXThread(Callable<V> callable)
runInJavaFXThreadback to summary
public static void runInJavaFXThread(Runnable runnable)

Runs the runnable later. This will guarantee that it runs on the FX UI Thread.

Parameters
runnable:Runnable

runnable BackgroundTask to run

runNowOrInJavaFXThreadback to summary
public static void runNowOrInJavaFXThread(Runnable runnable)

Runs the runnable now, when we are already on the FX UI Thread, or later if we are not.

Parameters
runnable:Runnable

runnable BackgroundTask to run

scheduleback to summary
public <V> Future<?> schedule(org.jabref.logic.util.BackgroundTask<V> task, long delay, TimeUnit unit)
Annotations
@Override
shutdownback to summary
public void shutdown()

Shuts everything down. After termination, this method returns.

Annotations
@Override