Thread 开启方式有两种.一种实现Thread,另一种继承RunableThread:
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.currentThread().setName("this is thread name");
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
LogUtil.d("this is thread from" + Thread.currentThread().toString());
}
}).start();
log:
(L:189): this is thread fromThread[this is thread name,5,main]
开始的Thread name为main.后来google找到这个.
原来log中的.toString()
中的源码是:
return "Thread[" + getName() + "," + getPriority() + "," +
group.getName() + "]";
最后一个是Thread Group name,是因为在main开启的.所以显示是main
© 著作权归作者所有
文章评论(0)