首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java中的照护线程

2012-12-20 
java中的守护线程public class testThread extends Thread {public testThread() {}/** *//*** 线程的run

java中的守护线程

public class testThread extends Thread {        public testThread() {    }    /** *//**     * 线程的run方法,它将和其他线程同时运行     */    public void run(){        for(int i = 1; i <= 100; i++){            try{                Thread.sleep(100);                            } catch (InterruptedException ex){                ex.printStackTrace();            }            System.out.println(i);        }    }    public static void main(String [] args){     testThread test = new testThread();        test.setDaemon(true);        test.start();        System.out.println("isDaemon = " + test.isDaemon());        try {            System.in.read(); // 接受输入,使程序在此停顿,一旦接收到用户输入,main线程结束,守护线程自动结束        } catch (IOException ex) {            ex.printStackTrace();        }    }}
?

热点排行