首页 > 其他 > 详细

Executor

时间:2016-02-21 00:15:34      阅读:289      评论:0      收藏:0      [点我收藏+]

1、Executor是任务执行器,该接口里面只含有一个方法。原来创建新的线程都是采用new Thread(new Runnable())的方式创建,该接口将原来提交任务的方式进行了进一步的抽象。

 /**

     * 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 <tt>Executor</tt> 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);

}   

2、ExecutorService   该接口继承自Executor,增加了线程管理器的生命周期的方法,比如shutdown,判断是否已shutdown,submit等方法。定义了完整的线程池的方法。

                    关闭线程池的两种方法:1shutdown()   会拒绝新的任务,但是会等待已提交的线程全部完成

                                                  2shutdownnow()会拒绝新的任务,同时结束正在运行中的任务。立刻结束

 

                    如何优雅的关闭线程池:

技术分享

技术分享

 

 

 

 

Executor

原文:http://www.cnblogs.com/YDDMAX/p/5204183.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!