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--);}}}}