/**
* 需求:简单的卖票程序
* 多个窗口同时卖票
*/
package java160108;
/**
* @author LiZheng
*
*/
public class TicketDemo {
/**
* @param args
*/
public static void main(String[] args) {
Ticket ticket1 = new Ticket();
Ticket ticket2 = new Ticket();
Ticket ticket3 = new Ticket();
Ticket ticket4 = new Ticket();
ticket1.start();
ticket2.start();
ticket3.start();
ticket4.start();
}
}
class Ticket extends Thread {
private static int tick = 100;//static的生命周期较长,在此程序中不建议使用
@Override
public void run() {
super.run();
while (true) {
if (tick > 0) {
System.out.println(currentThread().getName() + "sale..." + tick--);
}
}
}
}
* 需求:简单的卖票程序
* 多个窗口同时卖票
*/
package java160108;
/**
* @author LiZheng
*
*/
public class TicketDemo {
/**
* @param args
*/
public static void main(String[] args) {
Ticket ticket1 = new Ticket();
Ticket ticket2 = new Ticket();
Ticket ticket3 = new Ticket();
Ticket ticket4 = new Ticket();
ticket1.start();
ticket2.start();
ticket3.start();
ticket4.start();
}
}
class Ticket extends Thread {
private static int tick = 100;//static的生命周期较长,在此程序中不建议使用
@Override
public void run() {
super.run();
while (true) {
if (tick > 0) {
System.out.println(currentThread().getName() + "sale..." + tick--);
}
}
}
}