java 多线程买票案例
package com.tedu.threadStudy;
public class studyTicket {
public static void main(String[] args) {
YouThread youThread = new YouThread();
Thread thread = new Thread(youThread,"窗口1");
Thread thread2 = new Thread(youThread,"窗口2");
Thread thread3 = new Thread(youThread,"窗口3");
thread.start();
thread2.start();
thread3.start();
}
}
class YouThread implements Runnable{
int ticket = 100;
@Override
public void run() {
while (ticket>0){
System.out.println("正在售卖第"+(ticket--)+"张票");
}
// while (true){
// if (ticket>0){
// System.out.println(Thread.currentThread().getName()+"...卖出第"+(ticket--)+"张票");
// }else {
// break;
// }
// }
}
}
本文来自博客园,作者:竹石2020,转载请注明原文链接:https://www.cnblogs.com/ch2020/p/16867879.html
浙公网安备 33010602011771号