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

无锡网站制作计划沈阳建信建设工程有限公司位置

无锡网站制作计划,沈阳建信建设工程有限公司位置,速成网站,网站前台和后台这篇文章主要介绍了Java注解如何基于Redission实现分布式锁,文中通过示例代码介绍的非常详细#xff0c;对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下1、定义注解类Target({ ElementType.METHOD })Retention(RetentionPolicy.RUNTIME)Documentedpublic i…这篇文章主要介绍了Java注解如何基于Redission实现分布式锁,文中通过示例代码介绍的非常详细对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下1、定义注解类Target({ ElementType.METHOD })Retention(RetentionPolicy.RUNTIME)Documentedpublic interface DistributedLock {//锁名称String lockName() default ;//释放时间long releaseTime() default 5*1000;//时间单位TimeUnit timeUnit() default TimeUnit.MILLISECONDS;}2、定义切面拦截 DistributedLock 注解AspectComponentSlf4jpublic class DistributedLockAspect {Autowiredprivate RedissonClient redissonClient;//这里需要修改对应的包名Pointcut(annotation(com.utils.annotation.DistributedLock))public void RlockAspect() {}Around(RlockAspect())public Object arround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {Object object null;RLock lock null;log.info(rlockAspect start );try {DistributedLock rlockInfo getRlockInfo(proceedingJoinPoint);String lockKey getLocalKey(proceedingJoinPoint, rlockInfo);lock redissonClient.getLock(lockKey);if (lock ! null) {final boolean status lock.tryLock(rlockInfo.releaseTime(), rlockInfo.timeUnit());if (status) {object proceedingJoinPoint.proceed();}} else {log.info(未获取到锁{}, lockKey);}} finally {// 当前线程获取到锁再释放锁if (lock ! null lock.isHeldByCurrentThread()) {lock.unlock();}}return object;}public DistributedLock getRlockInfo(ProceedingJoinPoint proceedingJoinPoint) {MethodSignature methodSignature (MethodSignature) proceedingJoinPoint.getSignature();return methodSignature.getMethod().getAnnotation(DistributedLock.class);}/*** 获取redis lock key** param proceedingJoinPoint* return*/public String getLocalKey(ProceedingJoinPoint proceedingJoinPoint, DistributedLock rlockInfo) {StringBuilder localKey new StringBuilder(Rlock);final Object[] args proceedingJoinPoint.getArgs();String businessNo ;// 如果没有设置锁值if (StringUtils.isNotEmpty(rlockInfo.lockName())) {businessNo rlockInfo.lockName();} else {MethodSignature methodSignature (MethodSignature) proceedingJoinPoint.getSignature();Class[] parameters methodSignature.getParameterTypes();String methodName methodSignature.getMethod().getName();if (parameters ! null) {for (int i 0; i parameters.length; i) {Class parameter parameters[i];if (parameter.getSimpleName().equals(NDevice)) {NDevice de (NDevice) args[i];businessNo de.getUuid() methodName;}if (parameter.getSimpleName().equals(FrameBean)) {FrameBean de (FrameBean) args[i];businessNo de.getColumn1() methodName;}}// 如果没有获取到业务编号则使用方法签名if (StringUtils.isEmpty(businessNo)) {businessNo methodName;}}}return businessNo;}}3、使用方法在需要用分布式锁的方法上面加 DistributedLock 注解即可以上就是本文的全部内容希望对大家的学习有所帮助也希望大家多多支持脚本之家。
http://www.pierceye.com/news/462082/

相关文章:

  • 如果自己弄网站书签制作 小学生 一等奖
  • 连江网站建设wordpress页面文章列表
  • 国外jquery特效网站网站建设的英语
  • 建立网站最好的模板夜蝶直播app下载安装
  • 重庆学校网站建设wordpress 模版安装
  • 公司要招个做网站的人商标设计网站猪八戒
  • 古建设工程造价管理协会网站小程序引流推广平台
  • 网站域名缴费十年外贸建设企业网站服务
  • 游戏网站外链建设网站开发项目的需求分析
  • 确定网站的主题与风格东营市建设项目工伤保险是哪个网站
  • 如何做一张网站平面效果图装宽带需要多少钱
  • 什么网站能让小孩做算术题厦门住房和城乡建设局网站
  • 网站上线过程建设网站什么费用
  • 企业网站域名在哪申请成都广告公司
  • 手机页面网站模板怎么卖宁波网站建设优化找哪家
  • 深圳网站外包公司注册公司流程和费用找哪家
  • 专业新站整站快速排名公司商业网站和企业网站的区别
  • 网站做等保备案河北建设厅网站登陆怎么找附件
  • 网站前台显示数据库指定分类怎么做php优化大师官方免费
  • 用ps软件做ppt模板下载网站c2c网站开发策划
  • 标志空间 网站tk域名网站多少
  • dedecms网站地图插件永康公司网站开发
  • 比较网站建设有没有学做ppt发网站或论坛
  • 用asp做网站流程做科研找论文的网站
  • 新浪网站怎么做推广广告网站模板下载不了
  • 微网站建设哪家优惠h5小游戏在线玩
  • 娄底高端网站建设网站建设费计入 科目
  • 免费企业网站程序上传wordpress 卸载
  • 大庆市建设局网站上不去linux删除WordPress
  • 宣城市建设监督管理局网站下载怎么上wordpress