我也是参考其他博主的:
比如:
https://www.cnblogs.com/hujihon/p/5313731.html
下面是我自己看的一些源码+个人理解:
maxTotal:默认值8
解释:在指定时刻通过pool能够获取到的最大的连接的jedis个数
getMaxTotal():
Returns the maximum number of objects that can be allocated 分配指派 by the pool (checked out to clients, or idle awaiting checkout) at a given time. When negative, there is no limit to the number of objects that can be managed by the pool at one time.
Returns:the cap on the total number of object instances managed by the pool.
个人理解,在获取当时通过pool能够获取到的最大的连接的jedis个数(已经被客户端 连接上或者正在闲置等待客户端连接)
举例:
当我设置时,如果
for(int i=0;i<15;i++){
Jedis resource = jedisSentinelPool.getResource();
System.out.println(resource);
//resource.close();
}
如果没有close的话,只取到了10个连接:会报错:
报错截图:
当把resource.close();放开后:
没报错,每次都是取到一个对象:
maxIdle:默认值8
最大能够保持idle的数量,控制一个pool最多有多少个状态为idle的jedis实例
/*** Returns the cap on the number of "idle" instances in the pool. If maxIdle
* is set too low on heavily loaded systems it is possible you will see
* objects being destroyed and almost immediately new objects being created.
* This is a result of the active threads momentarily returning objects
* faster than they are requesting them them, causing the number of idle
* objects to rise above maxIdle. The best value for maxIdle for heavily