1、Executor

Executor接口中中只有一个方法

执行已提交的Runnable任务对象。

ExecutorService pool1 = Executors.newFixedThreadPool(5);
ExecutorService pool2 = Executors.newCachedThreadPool();
ExecutorService pool3 = Executors.newSingleThreadExecutor();
ExecutorService pool = Executors.newScheduledThreadPool(1);

这几种直接进入最终方法看吧

/**
* Creates a new {@code ThreadPoolExecutor} with the given initial
* parameters.
*
* @param corePoolSize the number of threads to keep in the pool, even
* if they are idle, unless {@code allowCoreThreadTimeOut} is set
* @param maximumPoolSize the maximum number of threads to allow in the
* pool
* @param keepAliveTime when the number of threads is greater than
* the core, this is the maximum time that excess idle threads
* will wait for new tasks before terminating.
* @param unit the time unit for the {@code keepAliveTime} argument
* @param workQueue the queue to use for holding tasks before they are
* executed. This queue will hold only the {@code Runnable}
* tasks submitted by the {@code execute} method.
* @param threadFactory the factory to use when the executor
* creates a new thread
* @param handler the handler to use when execution is blocked
* because the thread bounds and queue capacities are reached
* @throws IllegalArgumentException if one of the following holds:<br>
* {@code corePoolSize < 0}<br>
* {@code keepAliveTime < 0}<br>
* {@code maximumPoolSize <= 0}<br>
* {@code maximumPoolSize < corePoolSize}
* @throws NullPointerException if {@code workQueue}
* or {@code threadFactory} or {@code handler} is null
*/
public ThreadPoolExecutor(int corePoolSize,//coreSize
int maximumPoolSize,//maxSize
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,//有界队列和无界队列
ThreadFactory threadFactory,
RejectedExecutionHandler handler) {//拒绝策略或者其他操作,一个对象,可以用new RejectedExecutionHandler(),或者自定义
if (corePoolSize < 0 ||
maximumPoolSize <= 0 ||
maximumPoolSize < corePoolSize ||
keepAliveTime < 0)
throw new IllegalArgumentException();
if (workQueue == null || threadFactory == null || handler == null)
throw new NullPointerException();
this.corePoolSize = corePoolSize;
this.maximumPoolSize = maximumPoolSize;
this.workQueue = workQueue;
this.keepAliveTime = unit.toNanos(keepAliveTime);
this.threadFactory = threadFactory;
this.handler = handler;
}

Executor、ExecutorService、ThreadPoolExecutor的更多相关文章

  1. 多线程——Executor、ExecutorService、Executors三者的区别

    Executor.ExecutorService.Executors三者的区别: 层次关系: public interface ExecutorService extends Executor {} ...

  2. java中Executor、ExecutorService、ThreadPoolExecutor介绍(转)

    1.Excutor 源码非常简单,只有一个execute(Runnable command)回调接口 public interface Executor { /**     * Executes th ...

  3. java中Executor、ExecutorService、ThreadPoolExecutor介绍

    源码非常简单,只有一个execute(Runnable command)回调接口 public interface Executor { /**      * Executes the given c ...

  4. 001-多线程-JUC线程池-线程池架构-Executor、ExecutorService、ThreadPoolExecutor、Executors

    一.概述 1.1.线程池架构图 1. Executor 它是"执行者"接口,它是来执行任务的.准确的说,Executor提供了execute()接口来执行已提交的 Runnable ...

  5. Java多线程之Executor、ExecutorService、Executors、Callable、Future与FutureTask

    1. 引子 初学Java多线程,常使用Thread与Runnable创建.启动线程.如下例: Thread t1 = new Thread(new Runnable() { @Override pub ...

  6. (转)java中Executor、ExecutorService、ThreadPoolExecutor介绍

    转自: http://blog.csdn.net/linghu_java/article/details/17123057 ScheduledThreadPoolExecutor介绍: http:// ...

  7. 003-多线程-JUC线程池-几种特殊的ThreadPoolExecutor【newFixedThreadPool、newCachedThreadPool、newSingleThreadExecutor、newScheduledThreadPool】

    一.概述 在java doc中,并不提倡我们直接使用ThreadPoolExecutor,而是使用Executors类中提供的几个静态方法来创建线程池: 以下方法是Executors下的静态方法,Ex ...

  8. Java - 多线程Callable、Executors、Future

    http://blog.csdn.net/pipisorry/article/details/44341579 Introduction Callable接口代表一段能够调用并返回结果的代码; Fut ...

  9. Java并发编程 - Runnbale、Future、Callable 你不知道的那点事(二)

    Java并发编程 - Runnbale.Future.Callable 你不知道的那点事(一)大致说明了一下 Runnable.Future.Callable 接口之间的关系,也说明了一些内部常用的方 ...

随机推荐

  1. neutron openvswitch + vxlan 通讯

  2. 887. Super Egg Drop

    You are given K eggs, and you have access to a building with N floors from 1 to N. Each egg is ident ...

  3. 【文文殿下】ExBSGS

    无需逆元版本: #include<cstdio> #include<cassert> #include<cmath> #include<map> typ ...

  4. webstorm keymap

    http://www.jetbrains.com/webstorm/documentation/WebStorm_ReferenceCard.pdf

  5. apache测试网页执行效率

    apache软件下有一个测试网页访问速度的工具ab.exe,位于apache的bin目录下,windows下使用命令行进入bin目录,执行ab.exe -n 10000 -c 10 http://12 ...

  6. Java程序员的日常—— Spring Boot单元测试

    关于Spring boot 之前没有用Spring的时候是用的MockMvc,做接口层的测试,原理上就是加载applicationContext.xml文件,然后模拟启动各种mybatis\连接池等等 ...

  7. 为什么子元素设置margin-top会作用在父元素上?

    原因在于:CSS 外边距合并 复现: <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  8. ubuntu 中 mongodb 数据读写权限配置

    首先,我们先对mongodb 数据库的权限做一点说明: 1 默认情况下,mongodb 没有管理员账号 2 只有在 admin 数据库中才能添加管理员账号并开启权限 3 用户只能在所在的数据库中登录, ...

  9. Python中线程与互斥锁

    了解之前我们先了解一下什么是多任务? 概念: 几个不同的事件在同时运行就是多任务, 这样的话, 我们有牵扯到了真的多任务, 假的多任务; 并行: 真的多任务, 通过电脑的核数来确定 并发: 假的多任务 ...

  10. 最小化或关闭Outlook2013到系统托盘

    https://community.spiceworks.com/how_to/36214-minimize-and-or-close-outlook-to-taskbar 要注意里面提到的以管理员权 ...