package com.mischen.cn;
public class Demo2 {
public static void main(String[] args) {
SaleTicket s1=new SaleTicket();
Thread t1=new Thread(s1,"窗口1");
Thread t2=new Thread(s1,"窗口2");
Thread t3=new Thread(s1,"窗口3");
t1.start();
t2.start();
t3.start();
}
}
class SaleTicket implements Runnable{
int count=50;
@Override
public void run() {
while(true){
synchronized("锁"){
if(count>0){
System.out.println(Thread.currentThread().getName()+"售出了第"+count+"张票");
count--;
}else{
System.out.println("售罄了..");
break;
}
}
}
}
}
利用多线程写一个卖票程序
最新推荐文章于 2026-07-09 15:40:36 发布

1443

被折叠的 条评论
为什么被折叠?



