}
2. Thread类
1、Runnable接口源码:
1 public interface Runnable {
2 public void run();
3 }
2、Thread类与Runnable接口的继承关系
1 public class Thread implements Runnable{
2
3 }
Runnable接口仅有一个run()方法,Thread类实现了Runnable接口。
3、构造函数
1 public Thread() {
2 init(null, null, “Thread-” + nextThreadNum(), 0);
3 }
1 public Thread(Runnable target) {
2 init(null, target, “Thread-” + nextThreadNum(), 0);
3 }
1 public Thread(ThreadGroup group, Runnable target) {
2 init(group, target, “Thread-” + nextThreadNum(), 0);
3 }
1 public Thread(String name) {
2 init(null, null, name, 0);
3 }
还有其它的构造方法,此处省略。。。
这里的第三个参数是设置线程的名称,从下面的代码中可以看出,生成名称的规则是:”Thread-”加上创建的线程的个数(第几个)。
继续查看init方法:
1 /**
2 * Initializes a Thread.
3 *
4 * @param g the Thread group 5 * @param target the object whose run() method gets called 6 * @param name the name of the new Thread 7 * @param stackSize the desired stack size for the new thread, or 8 * zero to indicate that this parameter is to be ignored.
9 */
//T