-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
None
-
None
We have some parts in our code where we want to run some code in the FX Thread not later but immediately and to get exceptions thrown in the executed code.
We wrote a helper to realize this and it is very useful, maybe you can integrate it into JavaFX:
public static void run(Runnable runnable) {
if (Platform.isFxApplicationThread()) {
throw new IllegalStateException("Should NOT be invoked from FX Thread!");
}
CompletableFuture<Exception> runLaterPerformed = new CompletableFuture<>();
Runnable internalRunnable = new Runnable() {
@Override
public void run() {
Exception exception = null;
try {
runnable.run();
} catch (Exception e) {
exception = e;
}
runLaterPerformed.complete(exception);
}
};
Platform.runLater(internalRunnable);
Exception exception = runLaterPerformed.get();
if (exception != null) {
throw exception;
}
}
We wrote a helper to realize this and it is very useful, maybe you can integrate it into JavaFX:
public static void run(Runnable runnable) {
if (Platform.isFxApplicationThread()) {
throw new IllegalStateException("Should NOT be invoked from FX Thread!");
}
CompletableFuture<Exception> runLaterPerformed = new CompletableFuture<>();
Runnable internalRunnable = new Runnable() {
@Override
public void run() {
Exception exception = null;
try {
runnable.run();
} catch (Exception e) {
exception = e;
}
runLaterPerformed.complete(exception);
}
};
Platform.runLater(internalRunnable);
Exception exception = runLaterPerformed.get();
if (exception != null) {
throw exception;
}
}
- duplicates
-
JDK-8091974 Platform.runAndWait
-
- Open
-