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

江门营销网站建设网址界面

江门营销网站建设,网址界面,wordpress查看数据库密码,常用的网络营销方法文章目录 实现思路实现代码starter组件 实现思路 这里使用FutureTask#xff0c;它通过get方法以阻塞的方式获取执行结果#xff0c;并设定超时时间#xff1a; public V get() throws InterruptedException, ExecutionException ;public V get(long timeout, TimeUnit un… 文章目录 实现思路实现代码starter组件 实现思路 这里使用FutureTask它通过get方法以阻塞的方式获取执行结果并设定超时时间 public V get() throws InterruptedException, ExecutionException ;public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException ;利用spring aop解耦业务定义业务异常信息 实现代码 定义注解 Documented Retention(RetentionPolicy.RUNTIME) Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD}) public interface TimeoutCheck {/*** 超时时间默认5秒*/long timeout() default 5L;/*** 超时单位默认秒*/TimeUnit unit() default TimeUnit.SECONDS;/*** 超时后是否销毁线程*/boolean destroy() default true; } 这里有一个destroy()的方法因为我们在执行时开独立线程处理所以这个方法是为了在超时后用来判断是否销毁还在执行的线程 定义异常 注意这里的父类应该是项目中的基础业务异常类 public class TimeoutCheckException extends RuntimeException{public TimeoutCheckException(String message) {super(message);}public TimeoutCheckException(String message, Throwable throwable) {super(message, throwable);} } 再顺便定义一个属性配置 这个的作用是全局控制开关当不需要的时候可以直接通过配置关闭 Component ConfigurationProperties(prefix aliweb.timeout) public class TimeoutCheckProperties {private boolean enable true;public boolean isEnable() {return enable;}public void setEnable(boolean enable) {this.enable enable;} } 最后就是我们的aop类 Aspect Component public class TimeoutAop {private static final Logger logger LoggerFactory.getLogger(TimeoutAop.class);Autowiredprivate TimeoutCheckProperties timeoutCheckProperties;Pointcut(annotation(timeoutCheck))public void pointCut(TimeoutCheck timeoutCheck) {}Around(value pointCut(timeoutCheck), argNames joinPoint, timeoutCheck)public Object around(ProceedingJoinPoint joinPoint, TimeoutCheck timeoutCheck) throws Throwable {if (!timeoutCheckProperties.isEnable()) {return joinPoint.proceed();}long timeout timeoutCheck.timeout();if (timeout 0) {throw new TimeoutCheckException(业务逻辑执行时间不能小于等于0);}long start System.currentTimeMillis();String msg null;Exception error null;Object data null;FutureTaskObject futureTask createTask(joinPoint);try {Thread thread new Thread(futureTask);thread.start();data futureTask.get(timeout, timeoutCheck.unit());} catch (InterruptedException e) {msg 执行中断;error e;} catch (ExecutionException e) {msg 执行异常;error e;} catch (TimeoutException e) {msg 执行超时;error e;} finally {futureTask.cancel(timeoutCheck.destroy());}logger.debug(执行时间{}, System.currentTimeMillis() - start);if (error ! null) {String suf error.getMessage() null ? : error.getMessage();logger.error(msg suf, error);throw new TimeoutCheckException(msg suf, error);}return data;}private static FutureTaskObject createTask(ProceedingJoinPoint joinPoint) {return new FutureTask(() - {try {return joinPoint.proceed();} catch (Throwable e) {throw new RuntimeException(e);}});}} starter组件 将功能提取成starter组件: 定义配置类 Configuration ComponentScan(com.liry.aliweb.timeout) public class TimeoutCheckAutoConfig { } 定义配置扫描文件spring.factories路径 src/main/resources/META-INF/spring.factories org.springframework.boot.autoconfigure.EnableAutoConfigurationcom.liry.aliweb.timeout.config.TimeoutCheckAutoConfigpom增加依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-autoconfigure/artifactId /dependency如上在主项目引入时就可以直接使用了
http://www.hkea.cn/news/14263301/

相关文章:

  • 深圳哪个网站建设公司好名雕装饰
  • 在电脑上哪里可以做网站地方门户网站系统有哪些
  • 辽宁网站建设企业定制公司防蚊手环移动网站建设
  • 长沙哪里有专业做网站常熟市维摩剑门绿茶网站建设目标
  • 湖北高速公路建设网站工作服图片大全
  • 上海网站建设哪里便宜wordpress外观选单分类添加不
  • 佛山seo整站优化大连网建会
  • 广州网站建设市场使用html制作个人主页
  • 公司网站优化做网站建设最好的公司是
  • 保网微商城app下载百度seo怎么提高排名
  • 九江便宜做网站网站怎么做分时
  • 西平网站建设中国顺德手机网站设计
  • 音乐网站开发文档撰写模板广州建站免费模板
  • 公司网站客户案例泰安营销型网站建设公司
  • wordpress网站备案网站建设电话销售技巧
  • 北京网站建设制作哪家公司好新公司注册网站
  • 苏州外贸网站制作最近一周新闻大事摘抄2022年
  • WordPress多站点绑定域名网站开发实用技术知识点
  • 北京手机网站设计报价wordpress代码精简
  • 如何自己免费创建网站网站设计合同注意事项
  • 国外简洁的网站做跨境电商的步骤
  • 钓鱼网站下载辽宁住房和城乡建设厅网站首页
  • 重庆网站域名备案地址旅游分析 网站
  • 做网站和做软件一样吗合肥刚刚通报阳性
  • 淮安网站建设多少钱美食优秀设计网站
  • 网站建设技术公司柳州网站建设33
  • 小程序企业网站源码网站设计风格有几种
  • 天津设计师网站建筑工程公司需要什么资质
  • 网站举报网页设计模板设计
  • 关于学校的网站模板免费下载学校网站建设报价是多少