关闭。这个问题需要细节或清晰。它目前不接受答案。
**想改进这个问题吗?**通过编辑这个帖子来添加细节并澄清问题。
20小时前关门了。
改进这个问题
我正在学习java并尝试一些多线程的概念,我在ide上尝试过这个,但是输出正在改变。我想知道下面程序的输出-
class Work implements Runnable {
public void run() {
for (int i = 0; i < 5; i++) {
String tn = Thread.currentThread().getName();
System.out.println(tn);
}
String tn = Thread.currentThread().getName();
if (tn.equals("REST")) {
try {
Thread.currentThread().join();
} catch (Exception ex) {}
}
}
}
class Rest implements Runnable {
public void run() {
for (int i = 0; i < 5; i++) {
String tn1 = Thread.currentThread().getName();
System.out.println(tn1);
}
}
}
public class test1 {
public static void main(String[] args) {
Work w = new Work();
Rest r = new Rest();
Thread t1 = new Thread(w, "WORK");
Thread t2 = new Thread(r, "REST");
t1.start();
t2.start();
}
}
暂无答案!
目前还没有任何答案,快来回答吧!