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;
// }
// }
}
}
标签:java,Thread,YouThread,start,youThread,new,买票,多线程,ticket
From: https://www.cnblogs.com/ch2020/p/16867879.html