public class Fruit {
public static String fruit;
public static void main(String args[]) throws InterruptedException {
try {
Thread t = new AppleThread();
t.start();
} catch (IllegalThreadStateException e) {
System.out.println("Thread generated an error.");
}
fruit = "Orange";
Thread.sleep(100);
System.out.println(fruit);
}
private static class AppleThread extends Thread {
@Override
public void run() {
fruit= "Apple";
}
}
}
对我来说,它的核心有两个问题:1.)当引用Thread.sleep(100)时,它指的是哪个线程?
2。)我们与分配message =“ orange”的主线程并行执行t.start()。但是,苹果总是打印出来什么,为什么呢? “苹果”似乎总是获得最后的任务。
对此大体上的清理,我们深表感谢。
我无法理解为什么此代码多次运行后会打印“ Apple”而不是“ Orange”。有人可以帮忙吗? public class Fruit {公共静态字符串水果;公共静态void main(...
1。)当引用Thread.sleep(100)时,它指的是哪个线程?