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

苏州网站外包网站静态界面挖取

苏州网站外包,网站静态界面挖取,哪里有未成年做的网站,wordpress源码讲解一、使用Redisson步骤 Redisson各个锁基本所用Redisson各个锁基本所用Redisson各个锁基本所用 二、源码解析 lock锁 1#xff09; 基本思想#xff1a; lock有两种方法 一种是空参 另一种是带参 * 空参方法#xff1a;会默认调用看门狗的过期时间30*1000…一、使用Redisson步骤 Redisson各个锁基本所用Redisson各个锁基本所用Redisson各个锁基本所用 二、源码解析 lock锁 1 基本思想 lock有两种方法 一种是空参  另一种是带参          * 空参方法会默认调用看门狗的过期时间30*100030秒          * 然后在正常运行的时候会启用定时任务调用重置时间的方法间隔为开门看配置的默认过期时间的三分之一也就是10秒          * 当出现错误的时候就会停止续期直到到期释放锁或手动释放锁          * 带参方法手动设置解锁时间到期后自动解锁或者业务完成后手动解锁不会自动续期 源码 Lock 调用lockInterruptibly()方法会默认传入lease 为-1该值再后面起作用 public void lockInterruptibly(long leaseTime, TimeUnit unit) throws InterruptedException {long threadId Thread.currentThread().getId();//获取该锁的过期时间如果该锁没被持有会返回一个null如果被持有 会返回一个过期时间Long ttl this.tryAcquire(leaseTime, unit, threadId);if (ttl ! null) {//ttl不为null说明锁已经被抢占了RFutureRedissonLockEntry future this.subscribe(threadId);this.commandExecutor.syncSubscription(future);try {//开始循环获取锁while(true) {//刚进如循环先尝试获取锁获取成功返回null跳出循环获取失败则继续往下走ttl this.tryAcquire(leaseTime, unit, threadId);if (ttl null) {return;}if (ttl 0L) {//如果过期时间大于0则调用getLatch// 返回一个信号量开始进入阻塞阻塞时长为上一次锁的剩余过期时长并且让出cup//有阻塞必然有唤醒位于解锁操作中this.getEntry(threadId).getLatch().tryAcquire(ttl, TimeUnit.MILLISECONDS);} else {this.getEntry(threadId).getLatch().acquire();}}} finally {this.unsubscribe(future, threadId);}}} private T RFutureLong tryAcquireAsync(long leaseTime, TimeUnit unit, final long threadId) {//如果leaseTime -1即不等于默认值则表示手动设置了过期时间if (leaseTime ! -1L) {return this.tryLockInnerAsync(leaseTime, unit, threadId, RedisCommands.EVAL_LONG);} else {//如果leaseTime -1表示使用默认方式即使用看门狗默认实现自动续期RFutureLong ttlRemainingFuture this.tryLockInnerAsync(this.commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout(), TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_LONG);ttlRemainingFuture.addListener(new FutureListenerLong() {public void operationComplete(FutureLong future) throws Exception {//如果tryLockInnerAsync执行成功if (future.isSuccess()) {//获取过期时间Long ttlRemaining (Long)future.getNow();//过期时间为空表示加锁成功if (ttlRemaining null) {//开启刷新重置过期时间步骤RedissonLock.this.scheduleExpirationRenewal(threadId);}}}});return ttlRemainingFuture;}} // lua脚本尝试抢占锁失败返回锁过期时间T RFutureT tryLockInnerAsync(long leaseTime, TimeUnit unit, long threadId, RedisStrictCommandT command) {this.internalLockLeaseTime unit.toMillis(leaseTime);//直接使用lua脚本发起命令//通过lua脚本可以看出redisson加锁除了使用自定义的名字以外还要使用uuid// 加上当前线程的threadId组合以自定义名字作hash的key使用return this.commandExecutor.evalWriteAsync(this.getName(), LongCodec.INSTANCE, command,//如果该锁未被占有则设置锁设置过期时间过期时间为 internalLockLeaseTime 然后返回nullif (redis.call(exists, KEYS[1]) 0) then redis.call(hset, KEYS[1], ARGV[2], 1); redis.call(pexpire, KEYS[1], ARGV[1]);return nil; end; //如果锁已经被占有判断是否是重入锁如果是重入锁则将value增加1 代表重入并且设置过期时间返回null。if (redis.call(hexists, KEYS[1], ARGV[2]) 1) then redis.call(hincrby, KEYS[1], ARGV[2], 1); redis.call(pexpire, KEYS[1], ARGV[1]); return nil; end; //如果已经被站有所且不是重入锁则返回过期时间return redis.call(pttl, KEYS[1]);,Collections.singletonList(this.getName()), new Object[]{this.internalLockLeaseTime, this.getLockName(threadId)});} 看门狗续命 //看门狗续命机制private void scheduleExpirationRenewal(final long threadId) {//首先会判断该线程是否已经再重置时间的map中仅仅第一次进来是空的。if (!expirationRenewalMap.containsKey(this.getEntryName())) {//使用了看门狗默认的时间30秒 除以3 也就是延迟10秒后执行Timeout task this.commandExecutor.getConnectionManager().newTimeout(new TimerTask() {public void run(Timeout timeout) throws Exception {//判断是否该线程是否还持有锁如果持有返回1并且设置过期时间如果没持有返回0RFutureBoolean future RedissonLock.this.commandExecutor.evalWriteAsync(RedissonLock.this.getName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,if (redis.call(hexists, KEYS[1], ARGV[2]) 1) then redis.call(pexpire, KEYS[1], ARGV[1]); return 1; end; return 0;,Collections.singletonList(RedissonLock.this.getName()), new Object[]{RedissonLock.this.internalLockLeaseTime, RedissonLock.this.getLockName(threadId)});future.addListener(new FutureListenerBoolean() {public void operationComplete(FutureBoolean future) throws Exception {//从map中移除该线程这样下次再调用该方法仍然可以执行RedissonLock.expirationRenewalMap.remove(RedissonLock.this.getEntryName());if (!future.isSuccess()) {RedissonLock.log.error(Cant update lock RedissonLock.this.getName() expiration, future.cause());} else {if ((Boolean)future.getNow()) {//当lua脚本返回1表是true也就是仍然持有锁则递归调用该方法RedissonLock.this.scheduleExpirationRenewal(threadId);}}}});}}, this.internalLockLeaseTime / 3L, TimeUnit.MILLISECONDS);if (expirationRenewalMap.putIfAbsent(this.getEntryName(), task) ! null) {task.cancel();}}}2、unlock 源码 public RFutureVoid unlockAsync(final long threadId) {final RPromiseVoid result new RedissonPromise();//调用lua脚本释放锁RFutureBoolean future this.unlockInnerAsync(threadId);future.addListener(new FutureListenerBoolean() {public void operationComplete(FutureBoolean future) throws Exception {if (!future.isSuccess()) {result.tryFailure(future.cause());} else {Boolean opStatus (Boolean)future.getNow();//如果锁状态为null表示存在异常为正常释放锁之前被别人占领锁了if (opStatus null) {IllegalMonitorStateException cause new IllegalMonitorStateException(attempt to unlock lock, not locked by current thread by node id: RedissonLock.this.id thread-id: threadId);result.tryFailure(cause);} else {//如果返回0.为false 表示可重入锁不取消重置过期时间//返回1 为true表示已解锁取消重置过期时间if (opStatus) {RedissonLock.this.cancelExpirationRenewal();}//解锁result.trySuccess((Object)null);}}}});return result;}protected RFutureBoolean unlockInnerAsync(long threadId) {return this.commandExecutor.evalWriteAsync(this.getName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,//当key不存在表示锁未被持有说明不用解锁了返回1 1在后续表示取消重置过期时间if (redis.call(exists, KEYS[1]) 0) then redis.call(publish, KEYS[2], ARGV[1]); return 1; end; //key存在但是持有锁的线程不是当前线程返回null后面会提出一个异常if (redis.call(hexists, KEYS[1], ARGV[3]) 0) then return nil;end; //锁状态-1后仍然大于0表示可重入锁仍处于锁定状态返回00在后续表示 不做处理仍然重置过期时间local counter redis.call(hincrby, KEYS[1], ARGV[3], -1); if (counter 0) then redis.call(pexpire, KEYS[1], ARGV[2]); return 0; //返回锁状态不大于0正常解锁返回11在后续表示取消重置过期时间else redis.call(del, KEYS[1]); redis.call(publish, KEYS[2], ARGV[1]); return 1; end; return nil;, Arrays.asList(this.getName(), this.getChannelName()), new Object[]{LockPubSub.unlockMessage, this.internalLockLeaseTime, this.getLockName(threadId)});}
http://www.zqtcl.cn/news/689796/

相关文章:

  • 彩票网站开发 极云有的域名怎样做网站
  • 网店运营推广网站买个天猫店多少钱一个
  • 资讯网站排版广告公司取名大全集
  • 织梦网站seo安徽建设厅网站
  • 北京智能模板建站如何增加网站的索引量
  • 哪个网站专做进口商品的网站备案好麻烦
  • 南京网站制作哪家专业接口网站开发
  • 网站正在建设中9797鲜花网页设计模板
  • wordpress怎么自动更新网站地图现在最流行的网站开发工具
  • 科技局网站查新怎么做vs网站制作教程
  • 网站开发流程文档东莞英文建站公司
  • 怎样建俄文网站wordpress国产主题推荐
  • 网站开发晋升空间 路径秦皇岛房管局官网
  • 中山网站建设sipocms做家电网站好
  • 石家庄建设局网站怎么打不开手机网站素材
  • 电影网站怎么做要多少钱中企动力 网站价格
  • 长沙企业如何建网站爱用建站
  • 在哪个网站上做实验仪器比较好农村住宅设计图集
  • 网站的源代码有什么用wordpress英文博客模板下载
  • 用html5做网站的优点国内家居行业网站开发
  • 临沂企业网站客流统计系统厂家
  • 深圳H5网站开发最新版app下载安装
  • 手机网站免费模板下载成都建设项目环境影响登记网站
  • 上海网站seo公司网站建设公司盈利分析
  • 影评网站怎么做培训总结心得体会
  • 做微站比较好的网站注册子公司流程及所需资料
  • 网站 psd科技公司网站首页
  • 宁波论坛建站模板单页面视频网站
  • 冷饮网站开发背景意义大鱼直播
  • 网站如何建设二级域名代理天津专业做网站