java多线程模拟火车站窗口卖票的问题


package com.cal;

public class TicketsThread {
public static void main(String[] args) {

T tt=new T();

Thread thread=new Thread(tt,"窗口1");
Thread thread2=new Thread(tt,"窗口2");
Thread thread3=new Thread(tt,"窗口3");

thread.start();
thread2.start();
thread3.start();
}
}

class T implements Runnable{
//总的票数
private int count=5;

@Override
public void run() {
synchronized (this) {
while(count>0){
count--;
System.out.println(Thread.currentThread().getName()+"卖了一张票,还剩下"+count+"张票");
}
}
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM