package com.atguigu.java; /** * 例子:创建三个窗口卖票,总票数为100张 * @author Suki * @creat 2022-09-13 14:23 */ class window extends Thread{ private static int ticket = 100; @Override public void run() { while (true){ if(ticket > 0){ System.out.println("卖票,票号为:" + ticket); ticket--; }else{ break; } } } } public class WindowTest { public static void main(String[] args) { window w1 = new window(); window w2 = new window(); window w3 = new window(); w1.start(); w2.start(); w3.start(); } }
8.3 多线程练习,卖票
最新推荐文章于 2024-09-10 10:21:38 发布