Last updated on 2025-11-23T20:48:22+08:00
1. TODO
2. 脑图
Xmind
Edraw
Hexo 地址
👉 http://blog.wangjia.ink/2025/08/31/源码:java.util.concurrent.Executor源码解析/
3. 基础部分
3.1. Executor 概述
Executor 是一个接口,为我们提供了以下方法:
- 提交一个
Runnable 任务(非阻塞)
4. 源码部分
1 2 3 4 5 6
| public interface Executor { void execute(Runnable command); }
|
[!NOTE] 注意事项
- 详见源码:
Runnable
obsidian 内部链接:
- 源码:java.util.concurrent.Runnable源码解析
Hexo 链接:
- 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()); }); } } }
|