1.继承Thread类,重写run函数
2.实现Runnable,重写run函数
3.实现Callable接口,重写call函数
public class Test{
public static void main(String[] args){
var thread1 = new Thread(){
public void run(){
//logic
}
};
thread1.start();
Thread thread2 = new Thread(new Runnable(){
public void run(){
//logic
}
});
thread2.start();
FutureTask<Integer> futureTask = new FutureTask<>(new Callable<Integer>(){
public Integer call()throws Exception{
Thread.sleep(5000);
System.out.println("11111");
return 100;
}
});
Thread thread3 = new Thread(futureTask);
thread3.start();
System.out.println(futureTask.get());
}
}