一个线程常见的声明周期:
创建线程,start()方法之后,进入就绪状态,被cpu调度之后,进入运行状态,运行时,如果遭遇堵塞,进入堵塞状态,堵塞接触后,又重新
回到就绪状态,直到终止
线程的停止:1.内部执行完毕 2. 外部干涉(使用标识)
package cpm.thread.creater;
public class Demo1 {
public static void main(String[] args) {
study stu=new study();
new Thread(stu).start();
stu.stop();
}
}
class study implements Runnable
{
private Boolean flag=true;
@Override
public void run() {
while(flag)
{
System.out.println("11---");
}
}
public void stop()
{
this.flag=false;
}
}