本文介绍了就从非EDT美国东部时间(事件调度线程)线程的线程运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对EDT运行的方法和范围内,我希望把它在一个新的(非EDT)线程中执行一些东西。我现在的code为如下:

  @覆盖
    公共无效的actionPerformed(ActionEvent的为arg0){
从GUI //采集参数//低于code我希望在新的线程中运行,然后杀死此线程/(关闭的JFrame)
新GameInitializer(用户名,播放器,Constants.BLIND_STRUCTURE_FILES.get(blindStructure),handState);
}


解决方案

您可以创建并启动一个新的Java线程从EDT线程中执行你的方法:

  @覆盖
    公共无效的actionPerformed(ActionEvent的为arg0){        线程t =新主题(我的非EDT线){
            公共无效的run(){
                //我的工作
                新GameInitializer(用户名,播放器,Constants.BLIND_STRUCTURE_FILES.get(blindStructure),handState);
            }        };
        t.start();
    }

I have a method running on the EDT and within that I want to make it execute something on a new (non EDT) thread. My current code is follows:

@Override
    public void actionPerformed(ActionEvent arg0) {
//gathering parameters from GUI

//below code I want to run in new Thread and then kill this thread/(close the JFrame)
new GameInitializer(userName, player, Constants.BLIND_STRUCTURE_FILES.get(blindStructure), handState);
}
解决方案

You can create and start a new Java Thread that executes your method from within the EDT thread :

@Override
    public void actionPerformed(ActionEvent arg0) {

        Thread t = new Thread("my non EDT thread") {
            public void run() {
                //my work
                new GameInitializer(userName, player, Constants.BLIND_STRUCTURE_FILES.get(blindStructure), handState);
            }

        };
        t.start();
    }

这篇关于就从非EDT美国东部时间(事件调度线程)线程的线程运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 05:54
查看更多