package threadPage;//模拟火车站售票窗口,开启三个窗口售票,总数为100张class Window extends Thread{ static int ticket = 100; static Object obj = new Object(); public void run() { while (true) { synchronized (obj) { if (ticket > 0) { System.out.println(Thread.currentThread().getName()+"售票,票号:" + ticket--); } } } }}public class TestWindow { public static void main(String[] args) { Window w1 = new Window(); Window w2 = new Window(); Window w3 = new Window(); w1.start(); w2.start(); w3.start(); }}