当前位置: 代码迷 >> 综合 >> 四个线程在卖100张票
  详细解决方案

四个线程在卖100张票

热度:34   发布时间:2024-01-17 03:15:59.0
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--);}}}}


  相关解决方案