package com.Thread;
public class State {
public static void main(String[] args) {
Study s = new Study();
Thread t = new Thread(s);
t.start();
//外部干涉-->停止线程体
for(int i = 0; i<1000; i++) {
if(i==500) {
s.setFlag( false);
}
System. out.println("main Thread...." + i);
}
}
}
class Study implements Runnable {
//1、定义线体类中--->线程体使用标识
private boolean flag = true;
@Override
public void run() {
//2、线程体使用该标识
while(flag ) {
System. out.println("Study Tread...." );
}
}
//3、对外提供方法修改此标识
public void setFlag(boolean flag) {
this.flag = flag;
}
}