auto commit

This commit is contained in:
CyC2018
2020-01-09 00:52:33 +08:00
parent 5f005e2263
commit f84b140418
4 changed files with 12 additions and 10 deletions

View File

@ -68,22 +68,23 @@
- 实现 Callable 接口
- 继承 Thread
实现 Runnable Callable 接口的类只能当做一个可以在线程中运行的任务不是真正意义上的线程因此最后还需要通过 Thread 来调用可以任务是通过线程驱动从而执行的
实现 Runnable Callable 接口的类只能当做一个可以在线程中运行的任务不是真正意义上的线程因此最后还需要通过 Thread 来调用可以理解为任务是通过线程驱动从而执行的
## 实现 Runnable 接口
需要实现 run() 方法
通过 Thread 调用 start() 方法来启动线程
需要实现接口中的 run() 方法
```java
public class MyRunnable implements Runnable {
@Override
public void run() {
// ...
}
}
```
使用 Runnable 实例再创建一个 Thread 实例然后调用 Thread 实例的 start() 方法来启动线程
```java
public static void main(String[] args) {
MyRunnable instance = new MyRunnable();