Eug*_*ene 1 java multithreading
为什么主线程永远不会被执行?我认为这是我使用Thread.sleep(int value)我给其他线程运行的机会,但这永远不会发生.
public static void main(String[] args) {
final Sook o = new Sook();
Thread t = new Thread(new Runnable() {
public void run() {
while (true) {
try {
Thread.sleep(10000); // Specially set to give a chance to the main thread to run
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
t.run();
System.out.println("<<<<<BACK TO MAIN >>>>>>"); // Never happens
}
Run Code Online (Sandbox Code Playgroud)