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进行参数化调整。

  • 相关阅读:
    第三发
    第二发
    第一发
    要看的算法
    haxe坑
    TCP/IP协议三次握手与四次握手流程解析(转)
    Android动态类生成预加载-dexmaker使用
    Java中ArrayList 、LinkList区别
    Java解析YAML和Android解析YAML
    Java sax、dom、pull解析xml
  • 原文地址:https://www.cnblogs.com/duanxz/p/3400051.html
Copyright © 2011-2022 走看看