zoukankan      html  css  js  c++  java
  • canal 代码阅读

    涉及到有边界队列,无边界队列。poolSize、corePoolSize、maximumPoolSize 三者参数含义

    If there are more than corePoolSize but less than maximumPoolSize threads running, a new thread will be created only if the queue is full. By setting corePoolSize and maximumPoolSize the same, you create a fixed-size thread pool.

    he ThreadPoolExecutor has the following several key behaviors, and your problems can be explained by these behaviors.

    When tasks are submitted,

    1. If the thread pool has not reached the core size, it creates new threads.
    2. If the core size has been reached and there is no idle threads, it queues tasks.
    3. If the core size has been reached, there is no idle threads, and the queue becomes full, it creates new threads (until it reaches the max size).
    4. If the max size has been reached, there is no idle threads, and the queue becomes full, the rejection policy kicks in.

    In the first example, note that the SynchronousQueue has essentially size of 0. Therefore, the moment you reach the max size (3), the rejection policy kicks in (#4).

    问题就是使用SynchronousQueue,超过了maximumPoolSize还是能成功提交任务

    
    
    public static ThreadPoolExecutor newFixedThreadPool(int nThreads, long keepAliveTime) {
        return new ThreadPoolExecutor(nThreads,
            nThreads,
            keepAliveTime,
            TimeUnit.MILLISECONDS,
            new SynchronousQueue<>(),
            (r, exe) -> {
                if (!exe.isShutdown()) {
                    try {
                        exe.getQueue().put(r);
                    } catch (InterruptedException e) {
                        // ignore
                    }
                }
            });
    }
  • 相关阅读:
    工具类--map 转成xml xml转成map
    工具类--MD5Utils
    工具类--敏感信息掩码规则
    spring--Springmvc中@Autowired注解与@Resource注解的区别
    工具类--发送验证码短信
    工具类--日期工具类
    工具类--Excel 导出poi
    Jquery mobile中的 checkbox和radio的设置问题
    ASP和JS读写Cookie的问题
    js获取当前用户IP
  • 原文地址:https://www.cnblogs.com/studyNT/p/10780846.html
Copyright © 2011-2022 走看看