package Thread01;
public class MyThread extends Thread {
private int ticketNum = 10;
public MyThread(String name) {
super(name);
}
public void run() {
for (int i = 1; i <=100; i++) {
if (ticketNum>0) {
System.out.println(Thread.currentThread().getName()+":卖票"+(ticketNum--));
}
}
}
}
package Thread01;
public class RunnableTest implements Runnable{
private int ticketNum=10;
@Override
public void run() {
for (int i = 0; i <=100; i++) {
if (ticketNum >0) {
System.out.println(Thread.currentThread().getName()+":卖票"+(ticketNum--));
}
}
}
}
package Thread01;
public class Test {
public static void main(String[] args) {
RunnableTest t= new RunnableTest();
Thread t1=new Thread(t,"窗口一");
Thread t2=new Thread(t,"窗口二");
Thread t3=new Thread(t,"窗口三");
t1.start();
t2.start();
t3.start();
}
}