Javafx是否支持启动自己的线程? [英] Does Javafx support starting your own thread?

查看:130
本文介绍了Javafx是否支持启动自己的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的Javafx应用程序,它启动了一个新的线程,它可以从Netbeans中运行。
但我在编译期间收到以下警告:

I've wrote a simple Javafx application which starts a new thread and it works OK from Netbeans. But I'm getting following warning during compilation:

explicit use of threads is not supported

这是否意味着它现在可能适用于所有可能的设备,如手机或浏览器?

Does it mean that it might now work in all possible devices like mobile phones or browser?

推荐答案

JavaFX本身必须在主JavaFX线程上运行,因此目前不支持直接从JavaFX启动线程。但是,您可以创建一个生成Thread的Java类。因此,您的JavaFX类调用Java类,然后启动一个Thread。

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

从Java线程回调JavaFX,您需要在主JavaFX线程上。如何执行此操作的示例如下:

Calling back to JavaFX from a Java thread, you need to be on the main JavaFX thread. An example of how to do this is:

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

您不应直接从Java操作JavaFX对象。如果从Java执行,则需要使用javafx.reflect类。

You should not manipulate the JavaFX objects directly from Java. If you do it from Java, you need to use the javafx.reflect classes.

这篇关于Javafx是否支持启动自己的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆