java线程操作方法setName,getName,isAlive

来源:互联网 发布:优化加速软件 编辑:程序博客网 时间:2024/05/09 15:02
/** * ThreadDemo2.java * @author cjc * */public class ThreadDemo2{public static void main(String[] args){Thread th=new Thread(new TestThread());th.setName("子线程1");th.start();for(int i=0;i<10;i++){System.out.println("Thread "+Thread.currentThread().getName()+" is running...");System.out.println("Thread 子线程1 "+(th.isAlive()?"is":"is not")+" alive...");}}}
/** * TestThread.java * @author cjc * */public class TestThread implements Runnable{public void run(){for(int i=0;i<5;i++){System.out.println("Thread "+Thread.currentThread().getName()+" is running...");}}}


1 0
原创粉丝点击