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

dw课设做网站html基本知识

dw课设做网站,html基本知识,网站开发费用怎么账务处理,三亚按下了暂停键文章目录 实现思路实现代码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.dnsts.com.cn/news/196817.html

相关文章:

  • 无锡网络公司无锡网站推广网站建设周末培训
  • 网站开发亿玛酷技术网站建设规划设计任务书
  • 淘宝客网站怎么做推广策点市场调研公司
  • 三合一网站建设是指深圳建站公司模板
  • 陕西建设厅网站外贸公司网站开发步骤
  • 如何在百度推广网站seo 页面链接优化
  • 做网站前端难吗如何找外包网站来做
  • 国企网站建设合同网页浏览器没有声音
  • 建设工程专注在哪个网站烟台城乡建设局官方信息网站
  • 网站建设价格评审资料清单铜川做网站的公司
  • 揭阳网站建设托管江阴网站开发公司
  • 路桥网站建设网站服务器如何选择
  • 网站建设好了怎么做推广电子商务网站建设规划实践成果
  • 河南做网站送记账设计师网络用语
  • 设计一个企业网站多少钱高德地图无目的地导航
  • 即墨专业医院网站制作公司手机网站建设进度
  • 学校局域网站建设阿里云主机价格表
  • 网站建设的一些销售技巧dw个人网页设计
  • t恤定制网站网站内链检查
  • 网站视频播放代码wordpress5 源码
  • 自响应式网站建设清单上海网站建设排行
  • 个人如何做短视频网站高校宣传网站建设
  • 网站后台用户名什么是搜索推广
  • 阿里云服务器添加网站个人网站设计结构图
  • 怎样用FW做网站的首页互联网时代 网站建设
  • 天津商城网站设计公司用深度liunx做网站
  • 简述php网站开发流程图网站做seo推广 s
  • 网站如何做路由器温州网站设计服务商
  • 设计一个企业网站报价中国最新军事新闻
  • 如何搭建一个网站步骤网站制作毕业设计