

package com.bjsxt.thread.status;
public class StopDemo01 {
public static void main(String[] args) {
Study s = new Study();
new Thread(s).start();
//外部干涉
for(int i=0;i<100;i++) {
if(50==i) { //外部干涉
s.stop();
}
System.out.println("main...-->"+ i);
}
}
}
class Study implements Runnable{
//1)、線程類中 定義 線程體使用的標識
private boolean flag = true;
@Override
public void run() {
//2)、線程體使用該標識
while(flag) {
System.out.println("study Thread...");
}
}
//3)、對外提供方法改變標識
public void stop() {
this.flag = false;
}
}