线程的五大状态分别有,创建状态,就绪状态,运行状态,阻塞状态,和死亡状态
package BufferedTest;
?
public class TestStop1 implements Runnable{
?
private boolean flag = true;
@Override
public void run() {
int i = 0;
while (flag){
System.out.println("Run.....Thread"+i++);
}
?
}
public void stop(){
this.flag = false;
}
?
public static void main(String[] args) {
?
TestStop1 s1 = new TestStop1();
?
new Thread(s1).start();
?
for (int i = 0; i < 1000; i++) {
?
System.out.println("main"+i);
if(i == 900){
s1.stop();
System.out.println("线程该停止了");
}
}
?
}
}
线程的暂停