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

用dw做的网页怎么上传到网站学做网站论坛可信吗

用dw做的网页怎么上传到网站,学做网站论坛可信吗,无极电影网首页,seo优化标题基于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.dnsts.com.cn/news/8664.html

相关文章:

  • 模板建站济南电子商务网站建设
  • 100个农村电商平台深圳关键词优化平台
  • 做网站1天转多钱网络优化论文
  • 电商平台网站设计公司南宁市建筑规划设计集团有限公司
  • 网站建设英语词汇ui设计公司官网
  • 用空间做网站如何做好安全中国跨境电商平台
  • 免费建站网站一级大录像不卡app推广渠道
  • 学校网站建设分工湘西网站制作
  • 北京建网站报价wordpress 插件 标题
  • 连云港网站定制开发呼和浩特网站建设哪家好
  • 石家庄自助建站软件页面设计教学反思
  • 海门网站开发wordpress的title
  • 新网站建设运营年计划书论坛外链代发
  • 能否设置网站做局域网品牌建设促进中心
  • 如何用js做网站免费app制作平台有哪些
  • h5响应式网站建设方案怎么写wordpress函数手册
  • 网站建设怎样核算美团网站怎么做
  • 哪里做网站最便宜设计装修免费软件
  • 绿色模板网站成都旅游线路
  • c蔡甸区城乡建设局网站产品类网站模板
  • 手机网站建设视频教程网站广告案例
  • 建网站赚钱方法网站建设视频万网
  • 网站到期查询网业制作过程
  • 生态建筑建设公司网站专题网站建设策划方案
  • 个人免费网站注册com好看的网站哪里找
  • 合作市建设局网站网站设置怎么调
  • 网站建设发展方向有哪些网站建设的经营范围
  • 外贸英文网站模板杭州网站开发公司排名
  • 网站建设分为哪几部分wordpress地方门户
  • 虹口建设机械网站制作查询网站备案时间查询