Open ihenjoy opened 2 years ago
如果不做缓存,Redission每次去获取锁,都会new Redission Lock对象,对于吞吐量很大的服务,一秒几千上万次调用,那岂不是一秒也要创建出成千上万个对象出来?数据应该都正确的,重入锁应该需要重复利用,缓存起来吧?
参考源码,每次getLock都是new RedissonLock
public class Redisson implements RedissonClient {
...
@Override
public RLock getLock(String name) {
return new RedissonLock(commandExecutor, name);
}
...
}
这里可以不用作本地缓存,因为Redission 内部的重入本身就是按客户端id+线程id来判断的,这里加了本地缓存,如果业务key很多的话,就可能这里的内存占用会很大