下面是实际的问题代码编译的程序副本,查询在java中创建单独的线程?
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
public class Dummy {
public static boolean getUserCheck(int size, boolean Check) {
if (Check) {
int ret = JOptionPane.showConfirmDialog(null, size + " entries, Yes or no?",
"Warning", 0);
if (ret > 0) {
System.out.println("User said No: " + ret);
return false;
} else if (ret <= 0) {
System.out.println("user said Yes: " + ret);
return true;
}
}
return true;
}
public static void workerMethod1() {
System.out.println("am worker method 1");
}
public static void workerMethod2() {
System.out.println("am worker method 2");
}
public static void main(String[] args) {
System.out.println("mainthread code line 1");
int size = 13;
boolean thresholdBreach = true;
if (getUserCheck(size, thresholdBreach)) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
workerMethod1();
}
});
SwingUtilities.invokeLater(new Runnable() {
public void run() {
workerMethod2();
}
});
}
System.out.println("mainthread code line 2");
System.out.println("mainthread code line 3");
}
}
其中我想在主上单独的线程运行if{}
块()。由于这两条线,
System.out.println("mainthread code line 2");
System.out.println("mainthread code line 3");
不需要等待if(){}
块
的另一个问题是完成后,专家建议上运行事件线程确认,对话的方法。
int ret = JOptionPane.showConfirmDialog(null, size + " entries, Yes or no?",
"Warning", 0);
请帮我!!!!
是的,你可以,但你为什么要? –
这可能是一个XY问题类型的问题,但不管它是否是,问题都可以从更多的上下文中受益。你为什么要考虑这样做?你想达到什么样的总体目标? –
为什么你认为你不能将它嵌入到任意深度?测试任何代码时,您会考虑同样的观点。涵盖测试软件的所有要点是一个太广泛的问题。 –