【发布时间】:2019-06-30 17:16:01
【问题描述】:
我正在制作纸牌游戏应用程序。我有 2 个线程:
线程 curr = 这里保存的是当前线程(JavaFx 线程)
Thread proHs = 这里是app的大脑,通过Interface运行方法
我想停止线程 proHs 停止一秒钟,直到我选择这两个按钮中的一个 mam nemam
然后我必须返回 true 或 false。
我感谢任何建议或建议。 谢谢!
我试过无限循环
public boolean biddingStep(int gt) { //above this method is @Override, I can't post this with it
System.out.println(" ");
System.out.println("I HAVE OR NOT PART");
try {
proHs.wait();
}
catch (Exception e) {
System.out.print(e);
}
panelLicitace.setVisible(true);
mam.setVisible(true);
nemam.setVisible(true);
return false;//there would be the resolution of button "mam" or "nemam"
}
编辑#1
我想从你这里得到什么:
public boolean biddingStep(int gt) { //above this method is @Override, I can't post this with it
System.out.println(" ");
System.out.println("I HAVE OR NOT PART");
panelLicitace.setVisible(true);
mam.setVisible(true);
nemam.setVisible(true);
// HERE a code i want
//1. stop proHS thread
//2. loop program, wait for input from 2 buttons
//3. return true or false
}
【问题讨论】:
-
在共享
Object上的wait/notify,或在共享Condition上的await/signal,或者使用类似BlockingQueue的东西,并让JavaFX 线程将操作放入队列中其他线程将占用并执行。这些是线程通信的一些选项,但如果没有minimal reproducible example,我们将无法回答您的问题或查看您当前方法的问题(如果有);但是,proHs.wait()看起来不正确。
标签: java multithreading javafx