• 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并发编程的艺术》

  • 相关阅读:
    python的ORM框架SQLAlchemy
    SQLAlchemy技术文档(中文版)-下
    SQLAlchemy技术文档(中文版)-上
    python的class的__str__和__repr__(转)
    虚拟化技术之KVM
    cobbler部署安装
    pxe+kickstart 无人值守安装CentOS7.1
    超详细saltstack安装部署及应用
    页面缓存
    db2 常用命令
  • 原文地址:https://www.cnblogs.com/chen-msg/p/8426297.html
Copyright © 2020-2023  润新知