📄 preempt.java
字号:
public class Preempt implements Runnable{ public final static int TIMEOUT = 2000; public static void main(String args[]) { new Thread() { public void run() { try { Thread.sleep(TIMEOUT); } catch (InterruptedException _) { ; } System.exit(0); } }.start(); for (int i = 0; i < 5; i++) new Thread(new Preempt(), "thread " + i).start(); synchronized(Preempt.class) { System.out.println("started 5 threads"); } } public void run() { // this shouldn't be necessary---System.out.println should be // synchronized, but it apparently is (9/30/99) synchronized(Preempt.class) { System.out.println(Thread.currentThread().getName()); } while (true) { continue; } }}// Sort output/* Expected Output:started 5 threadsthread 0thread 1thread 2thread 3thread 4*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -