- java.lang.Object
-
- com.iamsoft.util.ui.javafx.TaskUtil
-
public final class TaskUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
callOnJavaFxThread(Supplier<T> pCallable)
static <S,T>
voidmapOnJavaFxThread(Stream<S> pStream, Function<S,T> pMapper, int pMaxStepDuration, Consumer<T> pConsumer)
This method blocks until all elements are processed.static void
onFinished(List<? extends javafx.concurrent.Task<?>> pTasks, Runnable pRunnable)
Runs the specified runnable when all of the specified tasks are cancelled or finished (successfully or not).static <T> T
runAndWait(Callable<T> pCallable)
Invokes the specified supplier on a background thread and waits without blocking UI.static <T> T
runAndWait(Callable<T> pCallable, long pTimeoutMillis)
Invokes the specified supplier on a background thread and waits without blocking UI.static <T> T
runAndWait(Callable<T> pCallable, Consumer<Runnable> pExecutor)
This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
.static <T> T
runAndWait(Callable<T> pCallable, Consumer<Runnable> pExecutor, Runnable pInterruptOp, long pTimeoutMillis)
This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
.static void
runLater(Runnable pRunnable)
This method can be used to run later a lot of runnables without flooding the event queue.static void
runLater(Runnable pRunnable, int pMinStepDuration)
This method can be used to run later a lot of runnables on steps.static void
runOnceLater(Runnable pRunnable)
This method can be used to run a runnable only once per run later event.
-
-
-
Method Detail
-
onFinished
public static void onFinished(List<? extends javafx.concurrent.Task<?>> pTasks, Runnable pRunnable)
Runs the specified runnable when all of the specified tasks are cancelled or finished (successfully or not).
-
runLater
public static void runLater(Runnable pRunnable)
This method can be used to run later a lot of runnables without flooding the event queue. Note that Platform.runLater(Runnable) is not a cheap operation.
-
runLater
public static void runLater(Runnable pRunnable, int pMinStepDuration)
This method can be used to run later a lot of runnables on steps.- Parameters:
pRunnable
- A non-null runnable to execute on the JavaFX thread.pMinStepDuration
- If there are enough runnables to run, specifies a minimum duration of how long the JavaFX thread should be blocked to run runnables before releasing the JavaFX thread and move to next step by running later again. Note that if there are previous runnables, which are not run yet, this argument will be ignored in favor of minimum step duration specified in previous call of this method.
-
runOnceLater
public static void runOnceLater(Runnable pRunnable)
This method can be used to run a runnable only once per run later event. Meaning that multiple invocations of this method for same runnable, happening before a run-later event occurs, will be ignored.
-
runAndWait
public static <T> T runAndWait(Callable<T> pCallable)
Invokes the specified supplier on a background thread and waits without blocking UI. This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
. It must not be called during animation or layout processing.
-
runAndWait
public static <T> T runAndWait(Callable<T> pCallable, long pTimeoutMillis)
Invokes the specified supplier on a background thread and waits without blocking UI. This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
. It must not be called during animation or layout processing.- Parameters:
pTimeoutMillis
- Duration in milliseconds to wait before giving up. Negative value or zero means indefinitely.
-
runAndWait
public static <T> T runAndWait(Callable<T> pCallable, Consumer<Runnable> pExecutor)
This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
. It must not be called during animation or layout processing.
-
runAndWait
public static <T> T runAndWait(Callable<T> pCallable, Consumer<Runnable> pExecutor, Runnable pInterruptOp, long pTimeoutMillis)
This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
. It must not be called during animation or layout processing.- Parameters:
pTimeoutMillis
- Duration in milliseconds to wait before giving up. Negative value or zero means indefinitely.
-
callOnJavaFxThread
public static <T> T callOnJavaFxThread(Supplier<T> pCallable)
-
mapOnJavaFxThread
public static <S,T> void mapOnJavaFxThread(Stream<S> pStream, Function<S,T> pMapper, int pMaxStepDuration, Consumer<T> pConsumer)
This method blocks until all elements are processed.- Parameters:
pMapper
- Invoked on the JavaFX thread to map elements.pMaxStepDuration
- If positive, will try to not block the JavaFX thread for more than this duration (in milliseconds), running later multiple times, if needed.pConsumer
- Invoked on the current thread to process the mapped elements.
-
-