Executor
来源:互联网 发布:matlab从excel导入数据 编辑:程序博客网 时间:2024/06/11 19:36
public interface Executor { /** * Executes the given command at some time in the future. The command * may execute in a new thread, in a pooled thread, or in the calling * thread, at the discretion of the {@code Executor} implementation. * * @param command the runnable task * @throws RejectedExecutionException if this task cannot be * accepted for execution * @throws NullPointerException if command is null */ void execute(Runnable command);}
command的执行可能在一个新线程,也可能在一个线程池中,或者在调用线程,具体由Executor到实现者决定。
可以自自定义实现Executor,官方实现有ExecutorService,ThreadPoolExecutor,Executors。
Executors是个工具类,能返回ExecutorService,ScheduledExecutorService,a "wrapped" ExecutorService,ThreadFactory,Callable。
public interface ThreadFactory { /** * Constructs a new {@code Thread}. Implementations may also initialize * priority, name, daemon status, {@code ThreadGroup}, etc. * * @param r a runnable to be executed by new thread instance * @return constructed thread, or {@code null} if the request to * create a thread is rejected */ Thread newThread(Runnable r);}
Executors中创建DefaultThreadFactory
/** * The default thread factory */ static class DefaultThreadFactory implements ThreadFactory { private static final AtomicInteger poolNumber = new AtomicInteger(1); private final ThreadGroup group; private final AtomicInteger threadNumber = new AtomicInteger(1); private final String namePrefix; DefaultThreadFactory() { SecurityManager s = System.getSecurityManager(); group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); namePrefix = "pool-" + poolNumber.getAndIncrement() + "-thread-"; } public Thread newThread(Runnable r) { Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0); if (t.isDaemon()) t.setDaemon(false); if (t.getPriority() != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY); return t; } }
0 0
- Executor
- Executor
- Executor
- Executor
- Executor
- Executor
- Executor
- Executor
- Executor
- Executor
- 【Java】【Executor】Executor 简介
- Executor框架
- Executor框架
- Executor 生命周期
- Executor框架
- Executor & ExecutorService
- Executor框架
- Executor框架
- Android触控基础:MotionEvent
- asp.net 生成验证码
- ubuntu备份与恢复
- LCA 最近公共祖先 小结
- 四轴飞行器初步——器件选择
- Executor
- Esper epl语句详解
- 建立TFTP下载调试
- 基于API的MFC串口通信程序编写
- iOS 类似淘宝商品详情查看翻页效果的实现
- 图像的七个不变矩 可用于图像的匹配
- 九度oj 1026
- Hibernate 执行原始SQL语句
- chapter18test1