读书人

Thread源码懂得

发布时间: 2012-10-10 13:58:11 作者: rapoo

Thread源码理解
1.首先看一下Runnable接口,只有一个run方法。???

??? Thread方法继承Runnable接口。

?3.构造函数

??? 在构造函数之前,Thread类中还有一个静态的代码块,这个是Object的方法,这里应该是重写了。

?还有在线程运行的时候还能改线程名字,并且各个线程的名字可以一样,用线程组管理的。

?

5.start方法。
//等待线程终止,public final synchronized void join(long millis)     throws InterruptedException {long base = System.currentTimeMillis();long now = 0;if (millis < 0) {            throw new IllegalArgumentException("timeout value is negative");}if (millis == 0) {    while (isAlive()) {wait(0);    }} else {    while (isAlive()) {long delay = millis - now;if (delay <= 0) {    break;}wait(delay);now = System.currentTimeMillis() - base;    }}    }
?总结:没看懂。倒是很好奇native里面写的是什么。

读书人网 >编程

热点推荐