本文主要是介绍App11_05_Runnable接口程序模拟航班售票系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//Runnable接口程序模拟航班售票系统--cool! Runnable接口适合处理多线程访问同一资源
class ThreadSale implements Runnable {private int tickets = 10;public void run() {while (true) {if (tickets > 0)System.out.println(Thread.currentThread().getName() + "售机票第"+ tickets-- + "号");elseSystem.exit(0);}}
}public class App11_5 {public static void main(String[] args) {ThreadSale t = new ThreadSale();// 只创建一个实现Runnable接口的售票类对象tThread t1 = new Thread(t, "第1售票窗口");Thread t2 = new Thread(t, "第2售票窗口");Thread t3 = new Thread(t, "第3售票窗口");t1.start();t2.start();t3.start();}}
这篇关于App11_05_Runnable接口程序模拟航班售票系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!