安卓开启Thread

2016-10-25 0 条评论 111 次阅读 0 人点赞

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

TestSmirk

这个人太懒什么东西都没留下

文章评论(0)