package com.javabasic.thread;
public class ThreadTest {
public static void attack() {
System.out.println("fight");
System.out.println("Current Thread is : " + Thread.currentThread().getName());
}
public static void main(String[] args) {
Thread t = new Thread() {
public void run() {
attack();
}
};
System.out.println("Current main thread is " + Thread.currentThread().getName());
t.run();
//Current main thread is main
//fight
//Current Thread is : main
t.start();
//Current main thread is main
//fight
//Current Thread is : Thread-0
// 调用start方法会创建一个新的子线程并启动
// run()方法只是thread的一个普通方法调用
}
}
调用start方法会创建一个新的子线程并启动,
run()方法只是thread的一个普通方法调用
二者并不具备可比性。
尚礼 求知 勤奋 谦逊 正直 公平
浙公网安备 33010602011771号