/**
* 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...");
}
}
}
java线程操作方法setName,getName,isAlive,布布扣,bubuko.com
java线程操作方法setName,getName,isAlive
原文:http://blog.csdn.net/cjc211322/article/details/25074715