netty之ConnectionProvider类型elastic和fixed区别
发布日期:2021-06-30 21:31:32
浏览次数:3
分类:技术文章
本文共 1531 字,大约阅读时间需要 5 分钟。
在Netty中存在四种创建连接的方式:
- newConnection:每次都是新链接
- elastic:弹性连接池
static ConnectionProvider elastic(String name, @Nullable Duration maxIdleTime, @Nullable Duration maxLifeTime) { return builder(name).maxConnections(Integer.MAX_VALUE) .pendingAcquireTimeout(Duration.ofMillis(0)) .pendingAcquireMaxCount(-1) .maxIdleTime(maxIdleTime) .maxLifeTime(maxLifeTime) .build(); }
- fixed:固定连接池
static ConnectionProvider fixed(String name, int maxConnections, long acquireTimeout, @Nullable Duration maxIdleTime, @Nullable Duration maxLifeTime) { if (maxConnections == -1) { return elastic(name, maxIdleTime, maxLifeTime); } if (acquireTimeout < 0) { throw new IllegalArgumentException("Acquire Timeout value must be positive"); } return builder(name).maxConnections(maxConnections) .pendingAcquireMaxCount(-1) // keep the backwards compatibility .pendingAcquireTimeout(Duration.ofMillis(acquireTimeout)) .maxIdleTime(maxIdleTime) .maxLifeTime(maxLifeTime) .build(); }
- builder:自定义连接池,通过bulider模式设置参数
builder(name).maxConnections(maxConnections) .pendingAcquireMaxCount(-1) // keep the backwards compatibility .pendingAcquireTimeout(Duration.ofMillis(acquireTimeout)) .maxIdleTime(maxIdleTime) .maxLifeTime(maxLifeTime) .build();
转载地址:https://lizz6.blog.csdn.net/article/details/109602933 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月12日 19时47分29秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【工具使用】新版CSDN-markdown编辑器使用指南
2019-04-30
【NLP学习笔记】中文分词(Word Segmentation,WS)
2019-04-30
【超越白皮书7】你需要知道关于ETH2.0的几个事实
2019-04-30
对于时间复杂度的通俗理解
2019-04-30
如何输入多组数据并输出每组数据的和?
2019-04-30
行阶梯型矩阵
2019-04-30
图像处理学习笔记
2019-04-30
MATLAB函数备忘(定期更新)
2019-04-30
13行MATLAB代码实现网络爬虫 爬取NASA画廊星图
2019-04-30
MATLAB指定路径保存图片方法
2019-04-30
Python一键获取微信推送封面图
2019-04-30
油猴脚本:微信推送浏览功能拓展
2019-04-30
JavaScript 表单操作与MD5加密
2019-04-30
JAVA学习笔记6 - 数组
2019-04-30
JAVA学习笔记8 - Stream 和 File I/O
2019-04-30
JAVA学习笔记9 - 异常
2019-04-30
JAVA学习笔记10 - 继承
2019-04-30
Android 开发学习笔记 00 - Getting Started
2019-04-30
【学习笔记】Android Activity
2019-04-30
Android使用Retrofit_00_Getting Started
2019-04-30