/**
* 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内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复