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

做卡贴质量好的网站网站开发的主要特点

做卡贴质量好的网站,网站开发的主要特点,wordpress 显示商品,桂市做网站的朋友基于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.hkea.cn/news/14521534/

相关文章:

  • 专业网站建设费用宜兴网站开发
  • 怎么做汽车网站推广方案毕业设计网站建设体会
  • 网站建设手机端页面模板技术支持 张家港网站建设
  • 简洁大方 网站wordpress简洁好用页脚代码
  • app网站开发公司的logo园林古建设计网站
  • 网站建设工作下步打算计算机前端
  • 兰州网站建设加王道下拉济南广告公司
  • 网站登陆注册怎么做注销网站 取消接入
  • 做网站可以在哪儿接活扶沟县建设局网站
  • 中国制药网网站开发技术设计家装的软件
  • 网站页面设计招聘展厅设计概念方案
  • nodejs可以做企业网站吗国外h5网站模板下载
  • app下载安装官方网站网页的优化与发布
  • 网站页面设计方案WordPress换主题文件夹
  • 江门市网站建设公司宣威网站建设公司
  • 网站下方一般放什么原因大学生网站作业
  • seo如何推广网站中国字体设计
  • 公司注册网站查询越众做的绿色建筑的网站
  • 免费文档网站有赞短网址生成
  • 怎么设计网站山东省建设管理中心网站首页
  • 青岛网站制作方法媒体网站怎么申请
  • 富平做网站邯郸网站建设公司
  • h5游戏网站建设网站框架地图
  • 公司网站维护和更新属于哪个部门seo专业实战培训
  • 门户网站的建设与维护个人注册公司查询
  • 音乐网站开发思路网站制作要学多久
  • 福州企业建站软件湛江高端网站建设
  • 做网站不用服务器网站建设方案.doc
  • 怎么建设局域网站网页设计与制作项目教程第二版
  • 查询域名是否做过网站网站开发建设与维护