Does Javafx support its own thread?

I wrote a simple Javafx application that launches a new thread, and it works fine with Netbeans. But during compilation, I get the following warning:

explicit use of threads is not supported

Does this mean that now it can work on all possible devices, such as mobile phones or a browser?

+3
source share
2 answers

JavaFX itself must run in the main JavaFX thread, so starting Thread directly from JavaFX is not currently supported. However, you can create a Java class that spawns Thread. So your JavaFX class calls the Java class, which then runs Thread.

JavaFX Java, JavaFX. , :

import com.sun.javafx.runtime.Entry;
Entry.deferAction( new Runnable() {
                    @Override
                    public void run() {
                        fxListener.onMessage(copy);
                    }
                } );

JavaFX Java. Java, javafx.reflect.

+1

JFXtras (http://jfxtras.org/) XWorker. , , , , JavaFX . , , , .

: http://jfxtras.googlecode.com/svn/site/javadoc/release-0.6/org.jfxtras.async/org.jfxtras.async.XWorker.html

:

 var currentImage:Image;
 var worker = XWorker {
     inBackground: function() {
         return Image {url: currentFile.toURL().toString(), height: imageHeight};
     }
     onDone: function(result) {
         currentImage = result as Image;
     }
 }

, inBackground, Swing. , onDone. onDone JavaFX Event Dispatch Thread ( , JavaFX), . . - , " ". , , , . JavaFX , , Java (, JPA EntityManager) , BlockingQueue. "/".

, , " ", /. :

 var worker = XWorker {
     inBackground: function() {
         while (true) {
           // Do something
           publish(someStuff);
         } 
     }
     process: function(someStuff: SomeStuff[]):Void {
       // Do something with some stuff. You are now in
       // "the foreground", so you can freely access 
       // JavaFX objects.
     }
     onDone: function(result) {
         currentImage = result as Image;
     }
 }

, , - .

0

Source: https://habr.com/ru/post/1751436/


All Articles