本文主要是介绍四个线程在卖100张票,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
package com.cavaness.quartzbook.chapter3;/*** 四个线程在卖100张票* @author Kevin**/
public class Test {public static void main(String[] args) {new TestThread().start();new TestThread().start();new TestThread().start();new TestThread().start();}
}
package com.cavaness.quartzbook.chapter3;public class TestThread extends Thread {private static int tickets = 100; // 一百张车票@Overridepublic void run() {while (true) {if (tickets > 0) {System.out.println("Method run:" + Thread.currentThread().getName() + " is saling " + tickets--);}}}}
package com.cavaness.quartzbook.chapter3;/*** 四个线程在卖100张票* @author Kevin**/
public class Test {public static void main(String[] args) {TestThread testThread = new TestThread();new Thread(testThread).start();new Thread(testThread).start();new Thread(testThread).start();new Thread(testThread).start();}
}
package com.cavaness.quartzbook.chapter3;public class TestThread implements Runnable {private static int tickets = 100; // 一百张车票@Overridepublic void run() {while (true) {if (tickets > 0) {System.out.println("Method run:" + Thread.currentThread().getName() + " is saling " + tickets--);}}}}
这篇关于四个线程在卖100张票的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!