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

/**
 * 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

java线程操作方法setName,getName,isAlive,布布扣,bubuko.com

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

上一篇:java.lang.IllegalArgumentException: Can't convert argument: null


下一篇:java线程的状态及操作方法