博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
dubbo 线程池
阅读量:4319 次
发布时间:2019-06-06

本文共 3202 字,大约阅读时间需要 10 分钟。

在dubbo调用过程中被调用方有两个线程池:io线程池,业务线程池。

这也是dubbo调优的点。

配置信息:

Dispatcher
  • all 所有消息都派发到线程池,包括请求,响应,连接事件,断开事件,心跳等。
  • direct 所有消息都不派发到线程池,全部在 IO 线程上直接执行。
  • message 只有请求响应消息派发到线程池,其它连接断开事件,心跳等消息,直接在 IO 线程上执行。
  • execution 只请求消息派发到线程池,不含响应,响应和其它连接断开事件,心跳等消息,直接在 IO 线程上执行。
  • connection 在 IO 线程上,将连接断开事件放入队列,有序逐个执行,其它消息派发到线程池。

 

ThreadPool
  • fixed 固定大小线程池,启动时建立线程,不关闭,一直持有。(缺省)
public class FixedThreadPool implements ThreadPool {    public Executor getExecutor(URL url) {        String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);        int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);        int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);        return new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS,                queues == 0 ? new SynchronousQueue
() : (queues < 0 ? new LinkedBlockingQueue
() : new LinkedBlockingQueue
(queues)), new NamedThreadFactory(name, true), new AbortPolicyWithReport(name, url)); }}

 

  • cached 缓存线程池,空闲一分钟自动删除,需要时重建。
public class CachedThreadPool implements ThreadPool {    public Executor getExecutor(URL url) {        String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);        int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS);        int threads = url.getParameter(Constants.THREADS_KEY, Integer.MAX_VALUE);        int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);        int alive = url.getParameter(Constants.ALIVE_KEY, Constants.DEFAULT_ALIVE);        return new ThreadPoolExecutor(cores, threads, alive, TimeUnit.MILLISECONDS,                queues == 0 ? new SynchronousQueue
() : (queues < 0 ? new LinkedBlockingQueue
() : new LinkedBlockingQueue
(queues)), new NamedThreadFactory(name, true), new AbortPolicyWithReport(name, url)); }}

 

  • limited 可伸缩线程池,但池中的线程数只会增长不会收缩。只增长不收缩的目的是为了避免收缩时突然来了大流量引起的性能问题。
public class LimitedThreadPool implements ThreadPool {    public Executor getExecutor(URL url) {        String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);        int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS);        int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);        int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);        return new ThreadPoolExecutor(cores, threads, Long.MAX_VALUE, TimeUnit.MILLISECONDS,                queues == 0 ? new SynchronousQueue
() : (queues < 0 ? new LinkedBlockingQueue
() : new LinkedBlockingQueue
(queues)), new NamedThreadFactory(name, true), new AbortPolicyWithReport(name, url)); }}

 

转载于:https://www.cnblogs.com/killbug/p/7588877.html

你可能感兴趣的文章
javascript Array(数组)
查看>>
HDU1518 Square 【剪枝】
查看>>
桥接模式
查看>>
android windows 上JNI编程
查看>>
PHP中可变变量到底有什么用?
查看>>
谈一谈最近关闭的Kindle人论坛
查看>>
android java 与C 通过 JNI双向通信
查看>>
javascript:另一种图片滚动切换效果思路
查看>>
获取css的属性值
查看>>
Win32_NetworkAdapterConfiguration
查看>>
Flash:DisplayObject的transform/matrix的潜规则、小bug
查看>>
方维系统常用的jquery库以及各个库的含义
查看>>
[LeetCode]101. Symmetric Tree
查看>>
Node.js的适用场景
查看>>
MongoDB 3.4 高可用集群搭建(二)replica set 副本集
查看>>
一个一线城市的IT白领的生活成本:3万/年
查看>>
ubuntu12.04 使用Adobe Reader PDF
查看>>
吃货联盟订餐系统(二)
查看>>
MessageBox 用法
查看>>
Developing school contest 2
查看>>