public class WindowT1 { public static void main(String[] args) { Windows1 w1 = new Windows1(); Windows1 w2 = new Windows1(); Windows1 w3 = new Windows1(); w1.setName("窗口一"); w2.setName("窗口二"); w3.setName("窗口三"); w1.start(); w2.start(); w3.start(); } } class Windows1 extends Thread { static int ticket = 100; static Object obj = new Object(); static boolean isFlag = true; public void run() { while(isFlag) { show(); } } public void show() { synchronized(Windows1.class) { if (ticket > 0) { try { Thread.sleep(10); } catch (InterruptedException e) { throw new RuntimeException(e); } System.out.println(Thread.currentThread().getName() + ":" + ticket); ticket--; } else { isFlag = false; } } } }