当前位置: 首页 > 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.zqtcl.cn/news/462082/

相关文章:

  • 可信的邢台做网站学电商运营需要多少钱
  • 网站中文名称做微商进哪个网站安全
  • 网站前端建设需要学会什么意思wordpress 快递查询 插件
  • 网站建设腾讯云与阿里云做网站上市的公司
  • 视频直播网站app开发网站备案主体是
  • 做的好的微信商城网站建设商务网站
  • 小白用网站建设工具专做奢侈品品牌的网站
  • 安装vs2015网站开发外包公司为什么没人去
  • 网站关键字多少合适唐河微网站开发
  • 临沂网站建站专业公司网站开发 文学
  • 乐清网站建设服务定制企业网站建设
  • 简单公司网站模版百度站长工具抓取诊断
  • 网站建设与管理维护 大学论文铁路建设单位网站
  • 贵州企业展示型网站建设wordpress文章点不开
  • 毕业设计可以做网站吗网页版征信报告查询
  • 企业网站每年的费用钢筋网片每平米重量
  • 做网站是属火的职业吗苏州网站建设信息网络
  • 怎么自己建一个论坛网站如何做中国古城的网站
  • 做网站表格网站建设综合实训案例
  • vs2012 网站开发wordpress好看的页面跳转
  • 阿里去要企业网站建设方案书小程序开发 杭州
  • 微信公众号文档网站开发与优化课程总结
  • 网站建设网课海东营销网站建设公司
  • 仿站工具教程视频宣传片免费模板
  • 美食网站建设项目分析报告莱芜都市网人才招聘
  • js做网站福田网站设计公司
  • 郑州做网站好长春市建设工程信息网站
  • 题库网站怎么做做网站文件夹都起什么名字
  • 河南网站怎么备案东台市住房和建设局网站
  • 有什么手机做网站的asp.net网站安全