java 线程 获取当前线程

java 线程 获取当前线程

 

 

Thread th=Thread.currentThread();

System.out.println("Tread name:"+th.getName());

th.setName("我的测试线程:");

System.out.println("Tread name:"+th.getName());

for (int i = 0; i < 5; i++) {
System.out.println(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

 

posted @ 2017-01-22 09:39  smallyaohailu  阅读(34550)  评论(0编辑  收藏  举报