线程池扩展

扩展说明

服务提供方线程池实现策略,当服务器收到一个请求时,需要在线程池中创建一个线程去执行服务提供方业务逻辑。

扩展接口

org.apache.dubbo.common.threadpool.ThreadPool

扩展配置

  1. <dubbo:protocol threadpool="xxx" />
  2. <!-- 缺省值设置,当<dubbo:protocol>没有配置threadpool时,使用此配置 -->
  3. <dubbo:provider threadpool="xxx" />

已知扩展

  • org.apache.dubbo.common.threadpool.FixedThreadPool
  • org.apache.dubbo.common.threadpool.CachedThreadPool

扩展示例

Maven 项目结构:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxThreadPool.java (实现ThreadPool接口)
  7. |-resources
  8. |-META-INF
  9. |-dubbo
  10. |-org.apache.dubbo.common.threadpool.ThreadPool (纯文本文件,内容为:xxx=com.xxx.XxxThreadPool)

XxxThreadPool.java:

  1. package com.xxx;
  2. import org.apache.dubbo.common.threadpool.ThreadPool;
  3. import java.util.concurrent.Executor;
  4. public class XxxThreadPool implements ThreadPool {
  5. public Executor getExecutor() {
  6. // ...
  7. }
  8. }

META-INF/dubbo/org.apache.dubbo.common.threadpool.ThreadPool:

  1. xxx=com.xxx.XxxThreadPool

最后修改 December 16, 2022: Fix check (#1736) (97972c1)