Mert Akozcan
Mert Akozcan

Reputation: 163

JavaFX Running WebEngine in another thread than FX Application Thread

As I stated in the title, is it possible to run WebEngine in another thread than FX Application Thread?

Code:

...
WebEngine webEngine = new WebEngine();

Thread thread = new Thread(() -> 
    webEngine.load("https://www.google.com"));
thread.setDaemon(true);
thread.start();
...

Exception:

Exception in thread "Thread-6" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-6
    at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:279)
    at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
    at javafx.scene.web.WebEngine.checkThread(WebEngine.java:1243)
    at javafx.scene.web.WebEngine.load(WebEngine.java:913)
    at sample.Main.lambda$start$0(Main.java:44)
    at java.lang.Thread.run(Thread.java:748)

Upvotes: 0

Views: 989

Answers (1)

Jan B.
Jan B.

Reputation: 6448

Regarding the Oracle documentation it's not possible.

WebEngine objects must be created and accessed solely from the JavaFX Application thread. This rule also applies to any DOM and JavaScript objects obtained from the WebEngine object.

Upvotes: 1

Related Questions