当前位置: 首页 > news >正文

杭州萧山区专业做网站的公司seo外链增加

杭州萧山区专业做网站的公司,seo外链增加,商丘网信办,济南优化seo网站建设公司redisson版本3.16.6 1.什么是看门狗 Redisson提供的分布式锁是支持锁自动续期的,也就是说,如果线程仍旧没有执行完,那么redisson会自动给redis中的目标key延长超时时间,这在Redisson中称之为 Watch Dog 机制。默认情况下&#x…
redisson版本3.16.6

1.什么是看门狗

Redisson提供的分布式锁是支持锁自动续期的,也就是说,如果线程仍旧没有执行完,那么redisson会自动给redis中的目标key延长超时时间,这在Redisson中称之为 Watch Dog 机制。默认情况下,看门狗的检查锁的超时时间是30秒钟,也可以通过修改Config.lockWatchdogTimeout来另行指定。

2.什么情况会续期

什么情况会续期,总结一句话:不传入leaseTime(锁自动释放时间),使用默认值-1

tryLock可传入参数有三个

lockName需要锁住的内容关键字

waitTime 获取锁最大等待时间,没有传-1

leaseTime锁自动释放时间,没有传-1

boolean tryLock 重载了三个方法,分别如下:

boolean tryLock(String lockName);boolean tryLock(String lockName, long waitTime) throws InterruptedException;boolean tryLock(String lockName, long waitTime, long leaseTime) throws InterruptedException;

从实现上看,使用才传参,不用,千万别主动写入-1,会对入参有校验。可以实现续期的情况只能使用前两个构造器,不能使用主动传入leaseTime的构造器。为什么这么说呢,源码如下:

方法都会调用tryLock获取锁,tryLock方法中调用tryAcquire方法

public boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException {long time = unit.toMillis(waitTime);long current = System.currentTimeMillis();long threadId = Thread.currentThread().getId();Long ttl = tryAcquire(waitTime, leaseTime, unit, threadId);// lock acquiredif (ttl == null) {return true;}....省略

tryAcquire方法会调用tryAcquireAsync,源码如下:

private <T> RFuture<Long> tryAcquireAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId) {RFuture<Long> ttlRemainingFuture;if (leaseTime != -1) {ttlRemainingFuture = tryLockInnerAsync(waitTime, leaseTime, unit, threadId, RedisCommands.EVAL_LONG);} else {ttlRemainingFuture = tryLockInnerAsync(waitTime, internalLockLeaseTime,TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_LONG);}ttlRemainingFuture.onComplete((ttlRemaining, e) -> {if (e != null) {return;}// lock acquiredif (ttlRemaining == null) {if (leaseTime != -1) {internalLockLeaseTime = unit.toMillis(leaseTime);} else {scheduleExpirationRenewal(threadId);}}});return ttlRemainingFuture;
}

从源码上看,只有当leaseTime为-1时scheduleExpirationRenewal这个方法才会生效,这个方法会进行续期。

3.续期源码分析

启一个task任务进行锁的自动续期

scheduleExpirationRenewal()->renewExpiration()

private void renewExpiration() {ExpirationEntry ee = EXPIRATION_RENEWAL_MAP.get(getEntryName());if (ee == null) {return;}// 启一个定时任务Timeout task = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {@Overridepublic void run(Timeout timeout) throws Exception {ExpirationEntry ent = EXPIRATION_RENEWAL_MAP.get(getEntryName());if (ent == null) {return;}Long threadId = ent.getFirstThreadId();if (threadId == null) {return;}// 核心续期代码,执行lua脚本RFuture<Boolean> future = renewExpirationAsync(threadId);future.onComplete((res, e) -> {if (e != null) {log.error("Can't update lock " + getRawName() + " expiration", e);EXPIRATION_RENEWAL_MAP.remove(getEntryName());return;}if (res) {// renewExpirationAsync执行成功,进行递归调用,调用自己,就可以实现不停的续期// 第一次执行这个函数,设置task任务,10s后执行task任务,刷新有效期,又重新设置一个task任务,10s后执行renewExpiration();} else {cancelExpirationRenewal(null);}});}// 定时任务是lockWatchdogTimeout的1/3时间去执行,就是每10s执行一次,renewExpirationAsync进行续期}, internalLockLeaseTime / 3, TimeUnit.MILLISECONDS);ee.setTimeout(task);
}

http://www.hkea.cn/news/620257/

相关文章:

  • 网站推广优化教程游戏代理加盟平台
  • 网站提升权重全国疫情高峰感染进度
  • 营销型网站怎么做智能建站abc
  • 捷信做单官方网站网络服务主要包括什么
  • 网站建设的方案费用什么时候网络推广
  • 这么做3d展示网站公司百度官网优化
  • 工业设计软件上市公司搜索引擎优化的方法
  • 网站建设公司创意网站网络推广推广
  • 浙江三建建设集团有限公司网站关键词的作用
  • 网站建设官方网站教育培训机构加盟十大排名
  • 万网上传网站seo免费
  • 孝感做网站公司百度热议排名软件
  • 建设网站费用吗廊坊seo快速排名
  • 网站建设公司怎样拓展网站业务大连网站推广
  • 什么网站可以免费做找客户东莞seo建站推广费用
  • 合肥微信网站建设购物网站如何推广
  • 网站建设课程简介图片百度官网认证免费
  • 月夜影视在线观看免费完整版韩剧关键词排名优化报价
  • 做网站的工作时间兰州seo公司
  • css怎么嵌入到html直通车关键词优化口诀
  • 虚拟网站php专业型seo网站关键词排名提升
  • 找人合伙做网站平台b2b电商平台
  • 手机网站建设技术方案找网站设计公司
  • 杭州如何设计公司网站惠州seo网站推广
  • 成都网站建设门户大连企业网站建站模板
  • 游戏卡充值可以做网站吗百度竞价关键词出价技巧
  • 建设企业网站就等于开展网络营销网店推广实训报告
  • dede无法更新网站主页到百度联盟注册
  • wordpress支持爱奇艺企业网站seo托管怎么做
  • 永川做网站的武汉百度快速排名提升