zoukankan      html  css  js  c++  java
  • Executor框架

    参看资料《java并发编程的艺术》

    ThreadPoolExecutor 实现线程池的基础类。

    封装好几个场景化线程池实现方式:

    1,FixedThreadPool

    FixedThreadPool被称为可重用固定线程数的线程池。FixedThreadPool使用无界队列LinkedBlockingQueue作为线程池的工作队列(队列的容量为Integer.MAX_VALUE)。

    2,SingleThreadExecutor

    SingleThreadExecutor是使用单个worker线程的Executor。SingleThreadExecutor使用无界队列LinkedBlockingQueue作为线程池的工作队列(队列的容量为Integer.MAX_VALUE)

    3,CachedThreadPool

    CachedThreadPool是一个会根据需要创建新线程的线程池。CachedThreadPool的corePoolSize被设置为0,即corePool为空;maximumPoolSize被设置为Integer.MAX_VALUE,即maximumPool是无界的。这里把keepAliveTime设置为60L,意味着CachedThreadPool中的空闲线程等待新任务的最长时间为60秒,空闲线程超过60秒后将会被终止。

    CachedThreadPool使用没有容量的SynchronousQueue作为线程池的工作队列,但CachedThreadPool的maximumPool是无界的。

    4,ScheduledThreadPoolExecutor

    ScheduledThreadPoolExecutor继承自ThreadPoolExecutor。

    它主要用来在给定的延迟之后运行任务,或者定期执行任务。

    https://www.jianshu.com/p/925dba9f5969

    FutureTask  使用

    FutureTask除了实现Future接口外,还实现了Runnable接口。因此,FutureTask可以交给
    Executor执行,也可以由调用线程直接执行(FutureTask.run())。

    ~~~*** 详情可查资料《java并发编程的艺术》

  • 相关阅读:
    ansible tower
    gitlab说明书
    新建系统配置
    docker&k8s-配置/常用命令
    Winscp隧道实现-跳板机/跨机连接
    FDM, FVM, FEM
    批量处理文件
    未来的职业规划
    内心两大矛盾
    MATLAB在Linux下的安装方法(待尝试)
  • 原文地址:https://www.cnblogs.com/chen-msg/p/8426297.html
Copyright © 2011-2022 走看看