package com.gxk.thread;
class ticketThread extends Thread {
private static int ticket = 50;
private String name;
public ticketThread(String name) {
this.name = name;
}
@Override
public void run() {
synchronized (this) {
while (ticket > 1) {
ticket--;
System.out.println(name + "卖出了一张票还剩" + ticket + "张票");
}
}
}
}
class ticket extends Thread {
public static void main(String[] args) {
ticketThread trd1 = new ticketThread("窗口1");
ticketThread trd2 = new ticketThread("窗口2");
ticketThread trd3 = new ticketThread("窗口3");
trd1.start();
trd2.start();
trd3.start();
}
}
java多线程实现售票
最新推荐文章于 2023-02-06 21:43:19 发布