netty之ConnectionProvider类型elastic和fixed区别
发布日期:2021-06-30 21:31:32 浏览次数:2 分类:技术文章

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

在Netty中存在四种创建连接的方式:

  1. newConnection:每次都是新链接
  2. 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();	}

     

  3. 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();	}

     

  4. 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:SpringCloudGateway源码解析:RemoveCachedBodyFilter
下一篇:jar启动no main manifest attribute, in .jar

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月26日 11时13分30秒