当前位置: 代码迷 >> 综合 >> 线程的stop
  详细解决方案

线程的stop

热度:64   发布时间:2024-01-17 03:13:24.0
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());}}
}


  相关解决方案