| Thread() 分配新的 Thread 对象。 |
Thread(ThreadGroup group,Runnable target,String name) 分配新的 Thread 对象,以便将 target 作为其运行对象,将指定的 name 作为其名称,并作为 group 所引用的线程组的一员。 |
Thread(ThreadGroup group,Runnable target,String name, long stackSize) 分配新的 Thread 对象,以便将 target 作为其运行对象,将指定的 name 作为其名称,作为 group 所引用的线程组的一员,并具有指定的堆栈大小。 |
public class Test1 {
public static void main(String[] args) {
System.out.println(Thread.currentThread().getName());
MyThread myThread=new MyThread();
myThread.start();
}
}
class MyThread extends Thread{
int i=0;
@Override
public void run() {
while (i<10) {
System.out.println(this.getName()+" i的值 "+i);
i++;
}
public class Test1 {
public static void main(String[] args) {
System.out.println(Thread.currentThread().getName());
Thread thread=new Thread(new MyRunnable());
thread.start();
}
}
class MyRunnable implements Runnable{
int i=0;
@Override
public void run() {
while (i<10) {
System.out.println(Thread.currentThread().getName()+" i的值 "+i);
i++;
}
}
} | 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |