源码:java.util.concurrent.Executor 源码解析

1. TODO


2. 脑图

  1. Xmind

  2. Edraw

  3. Hexo 地址
    👉 http://blog.wangjia.ink/2025/08/31/源码:java.util.concurrent.Executor源码解析/


3. 基础部分

3.1. Executor 概述

Executor 是一个接口,为我们提供了以下方法:

  1. 提交一个 Runnable 任务(非阻塞)

4. 源码部分

1
2
3
4
5
6
public interface Executor {

// 用于非阻塞提交一个 Runnable 任务
void execute(Runnable command);

}

[!NOTE] 注意事项

  1. 详见源码:Runnable
    1. obsidian 内部链接:
      1. 源码:java.util.concurrent.Runnable源码解析
    2. Hexo 链接:
      1. http://blog.wangjia.ink/2025/09/02/源码:java.util.concurrent.Runnable源码解析/

5. 实现示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class DemoExecutor implements Executor {

@Override
public void execute(Runnable command) {
if (command == null) {
throw new NullPointerException("Runnable 不能为 null");
}
new Thread(command).start();
}

public static void main(String[] args) {
Executor executor = new DemoExecutor();
for (int i = 1; i <= 3; i++) {
int id = i;
executor.execute(() -> {
System.out.println("执行任务 " + id + " 的线程: " + Thread.currentThread().getName());
});
}
}

}


源码:java.util.concurrent.Executor 源码解析
https://wangjia5289.github.io/2025/08/31/源码:java.util.concurrent.Executor源码解析/
Author
咸阳猴🐒
Posted on
August 31, 2025
Licensed under