zoukankan      html  css  js  c++  java
  • juc线程池原理(六):jdk线程池中的设计模式

    一、jdk中默认线程池中的代理模式

    单例类线程池只有一个线程,无边界队列,适合cpu密集的运算。jdk中创建线程池是通过Executors类中提供的静态的方法来创建的,其中的单例类线程池的方法如下:

    public static ExecutorService newSingleThreadExecutor()
    {
        return new FinalizableDelegatedExecutorService(new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()));
    }
    
    public static ScheduledExecutorService newSingleThreadScheduledExecutor()
    {
        return new DelegatedScheduledExecutorService(new ScheduledThreadPoolExecutor(1));
    }

    说明:

    1、newSingleThreadExecutor的代理模式类图如下:

    new ThreadPoolExecutor()实例是被代理对象作为参数传给代理对象FinalizableDelegatedExecutorService,通过代理对象限制对ThreadPoolExecutor进行参数化调整。
    2、newSingleThreadScheduledExecutor的代理模式类图如下:



    new ScheduledThreadPoolExecutor(1)实例是被代理对象作为参数传递给代理对象DelegatedScheduledExecutorService,通过代理对象限制对ThreadPoolExecutor进行参数化调整。

  • 相关阅读:
    redhat7 安装 mysql5.7
    python django 网站局域网问
    SQLiteStudio
    升级gcc到gcc-8.1.0
    [SAP HANA ]fulltext index
    [ORACLE] SNC 学习
    [oracle]sqlplus 输出格式化print_table学习
    win-->linux 文本转换
    [ORACLE]ORA-03113: end-of-file on communication channel
    ORACLE 在线重定义分区表
  • 原文地址:https://www.cnblogs.com/duanxz/p/3400051.html
Copyright © 2011-2022 走看看