视频地址:https://www.bilibili.com/video/BV1Jx411a7Dp
1. 继承Thread类,重写run()方法
1 | class MyThread extends Thread { |
1 | Thread-0 线程启动 |
2. 实现Runnable接口,并重写run()方法
1 | class MyRunnable implements Runnable { |
1 | Thread-0 线程启动 |
3. 实现Callable接口,重写call()方法
- FutureTask类实现了RunnableFuture接口,RunnableFuture接口继承了Runnable接口
- FutureTask类中有一个参数为Callable类型的构造方法。
1 | class MyCallable implements Callable<String> { |
1 | 实现Callable接口来创建线程 |