线程的shut down方法

来源:互联网 发布:ssh连接阿里云centos 编辑:程序博客网 时间:2024/05/16 02:53

线程的shut down方法


public class TestThread4 {public static void main(String args[]){Runner4 r = new Runner4();       Thread t = new Thread(r);        t.start();        for(int i=0;i<100000;i++){        if(i%10000==0 & i>0)        System.out.println("in thread main i=" + i);        }        System.out.println("Thread main is over");        r.shutDown();    }}class Runner4 implements Runnable {  private boolean flag=true;  public void run() {int i = 0;while (flag) {System.out.print(" " + i++);}}  public void shutDown() {flag = false;  }}


原创粉丝点击