package com.cavaness.quartzbook.chapter3;/*** 线程通信问题*/
public class Test {public static void main(String[] args) {TestThread testThead = new TestThread();new Thread(testThead).start();for (int i = 0; i < 2000; i++) {if (i == 50) {testThead.setbStop(true);}System.out.println(Thread.currentThread().getName());}}
}
package com.cavaness.quartzbook.chapter3;public class TestThread implements Runnable {private boolean bStop = false;public boolean isbStop() {return bStop;}public void setbStop(boolean bStop) {this.bStop = bStop;}@Overridepublic void run() {while (!bStop) {System.out.println(Thread.currentThread().getName());}}
}