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

建设银行客户端官方网站成都关键词优化服务

建设银行客户端官方网站,成都关键词优化服务,潍坊个人做网站,wordpress contact基于Redis加锁注解AOP解决JOB重复执行问题 现象解决方案自定义注解定义AOP策略redis 加锁实践 现象 线上xxljob有时候会遇到同一个任务在调度的时候重复执行#xff0c;如下图#xff1a; 线上JOB服务运行了2个实例#xff0c;有时候会重复调度到同一个实例#xff0c;有… 基于Redis加锁注解AOP解决JOB重复执行问题 现象解决方案自定义注解定义AOP策略redis 加锁实践 现象 线上xxljob有时候会遇到同一个任务在调度的时候重复执行如下图 线上JOB服务运行了2个实例有时候会重复调度到同一个实例有时候会重复调度到不同实例上对于Job重复执行会存在很多风险可以采用Redis加锁的方式来解决。这里用统一的方式提供这个内部功能其他Job或者从管理页面进来的请求直接执行Job可以都限制住保证同一时间分布式环境中只有一个实例在运行。 解决方案 自定义注解 首先定义一个自定义注解将redis加锁需要的参数可以通过注解声明 Target({ElementType.METHOD}) Retention(RetentionPolicy.RUNTIME) public interface JobNoRepete { String name(); String redisKey(); long expireTime(); TimeUnit timeUnit(); }定义AOP策略 Component Aspect Slf4j public class JobNoRepeteAop { Resourceprivate RedisService redisService; Around(value annotation(annotation), argNames pj,annotation)public Object around(ProceedingJoinPoint pj, JobRepetitionDefense annotation) throws Throwable {String name annotation.name();String redisKey annotation.redisKey();long expireTime annotation.expireTime();TimeUnit timeUnit annotation.timeUnit();log.info(job执行防重开始执行,name{},redisKey{},expireTime{},timeUnit{},name, redisKey, expireTime, timeUnit);try {return redisService.executeOnlyOnce(redisKey, expireTime, timeUnit, pj::proceed);} finally {log.info(job执行防重执行完成,name{}, name);}}}redis 加锁 redis 加锁逻辑使用spring redis中的StringRedisTemplate Slf4j Component public class RedisService {Resourceprivate StringRedisTemplate stringRedisTemplate;public T T executeOnlyOnce(String redisKey, long expireTime, TimeUnit timeUnit, CustomCallableT callable) throws Throwable {if (StrUtil.isBlank(redisKey) || expireTime 0 || Objects.isNull(timeUnit) || Objects.isNull(callable)) {throw new IllegalArgumentException(参数错误);}String uuid UUID.randomUUID().toString();if (!stringRedisTemplate.opsForValue().setIfAbsent(redisKey, uuid, expireTime, timeUnit)) {throw new RuntimeException(任务正在执行,请稍后再试);}//执行逻辑try {return callable.call();} finally {//执行完成主动释放锁try {String oldValue stringRedisTemplate.opsForValue().get(redisKey);if (Objects.equals(uuid, oldValue)) {stringRedisTemplate.delete(redisKey);}} catch (Exception e) {//释放锁失败等待expireTime后自动释放log.error(释放锁异常, e);}}} } public interface CustomCallableV {V call() throws Throwable; }实践 对于适用的场景就可以直接使用注解的方式进行声明例如 Service Slf4j public class testService { private static final int EXPIRE_HOURS 24; JobNoRepete(name 测试redis, redisKey Constant.JOB_LOCK_TO_REDIS,expireTime EXPIRE_HOURS, timeUnit TimeUnit.HOURS)public void test(LocalDate localDate) {//内部逻辑} }
http://www.pierceye.com/news/307198/

相关文章:

  • 南京 电子商务网站5118数据分析平台官网
  • 试析企业网站建设模式建网站的网络公司
  • 内蒙古建设 招聘信息网站平台搭建
  • 做网站公司共有几处密码公司seo营销
  • 镇江网站制作费用广东华电建设股份有限公司网站
  • 西安知名的集团门户网站建设服务商潍坊网站开发asp培训
  • 网站服务器连接被重置为什么高德地图没有外国位置信息
  • 帝国cms 仿站 wordpress天津新亚太工程建设监理有限公司网站
  • 精品网站导航 做最好的导航网站建设数据库选择
  • 蓝杉网站建设公司贵阳网站建设公司排名
  • 苏州专业高端网站建设机构建网站公司下载快手
  • 中堂仿做网站个人网站设计论文道客巴巴
  • 怎么用ps做网站效果图24什么网站建设
  • 网站开发技术有网站建设方案 pdf
  • 网站建设教程浩森宇特福州医院网站建设公司
  • 怎样在网站上做超链接网站商城是用什么框架做的
  • 网站建设增城wordpress新文章类型
  • 广州市招投标中心官网上海网站关键词优化
  • 很多网站开发没有框架如何制作的长沙旅游景点大全排名
  • 云南网站推广的目的做动画的网站有哪些
  • 网站建设公司在哪里找资源模拟建设网站
  • 如何盗用网站模板哈尔滨公告
  • 管理咨询网站焦作专业做网站公司哪家好
  • 在国内做跨境电商怎么上外国网站网站不收录
  • 网站介绍ppt怎么做屏蔽网站ip
  • it公论 是建立在什么网站wordpress搬迁数据库连接失败
  • 南县建设局网站营销型网站开发流程包括
  • 有关应用网站申请免费网站空间
  • 二手书交易网站开发现状营销型网站建设推荐乐云seo
  • 山西网站建设怎么样seo优化网站多少钱