1. 创建线程方法
创建线程目前我就掌握了三种方法
- 继承了Thread,主要是搭配第一种
//继承了Thread,主要是搭配第一种
public class UserThread extends Thread {
@Override
public void run() {
System.out.println("this is myThread! ");
}
}
- 实现Runnable,主要搭配第二种
// 实现Runnable,主要搭配第二种
public class SecondThread implements Runnable {
@Override
public void run() {
System.out.println(" this is my another second thread!");
}
}
- 实现Callable接口,主要搭配第三种
public class ThreeThread implements Callable<User> {
@Override
public User call() throws Exception {
System.out.println("this is my three thread");
return new User("2","ligel",10);
}
}
- 创建线程的方法如下
public class CreateThread {
public static