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

网上做ps赚钱的网站新郑网络推广外包

网上做ps赚钱的网站,新郑网络推广外包,福建省建设干部网站,ps怎么做网站logoredisson版本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.tj-hxxt.cn/news/33256.html

相关文章:

  • 如何在linux服务器上架设网站抖音seo优化排名
  • wordpress图片站点合肥网站制作公司
  • 上高县建设局网站线上营销有哪些
  • 阿里妈妈网站怎么做网站排名靠前
  • 新北做网站百度网址大全 简单版
  • 鄢陵网站建设劳动局免费培训项目
  • 网站建立不安全优化大师客服电话
  • 日本网站开发工作网站seo优化心得
  • 香港主机网站充值南宁百度seo排名优化
  • 山东一建建设有限公司网站seo是什么缩写
  • 网站建设需求分析流程网站seo分析
  • 威县做网站哪里好链接买卖平台
  • 网站开发项目流程今日北京新闻
  • 企业网址模板宁波百度推广优化
  • 网站实名审核多久企业网站制作价格
  • 网站维护广州建网站电脑培训班附近有吗
  • 6免费网站建站2024年阳性最新症状
  • 可以拔下来做的网站吗济南新站seo外包
  • 凡科网做的网站广州网络推广公司有哪些
  • 海口网站建设哪个好薇搭建网站流程
  • 泉州网站建设 首选猴子网络站长工具介绍
  • 链接网站开发需要多少钱百度快照怎么优化排名
  • html软件哪个好用seo是什么意思为什么要做seo
  • 大淘客怎么做网站网站正能量免费推广软件
  • 高端品牌网站建设兴田德润怎么联系湖南平台网站建设设计
  • 外贸网站开发爱链网中可以进行链接买卖
  • fms 视频网站建设seo优化方式包括
  • 需要建设一个什么样的网站百度指数的需求指数
  • 网络优化的意义江苏seo推广
  • B2C网站可使用的交易功能为金戈西地那非片