当前位置: 首页 > 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.yingshimen.cn/news/47463/

相关文章:

  • 养殖场网站模板网站用户界面设计
  • 上海市企业服务云官网优化关键词步骤
  • 建设网站主题金融电子商务网站建设
  • 深圳网站建设设计平台电子商务网站开发实践
  • 班级网站建设感想中国前十强企业
  • wordpress用户登录注册插件中山网站搜索引擎优化
  • 湖南建设教育网站孝感市门户网站
  • 移动app做的好的网站wordpress英文仿站
  • c 做网站性能怎么样宜昌 医院 网站建设
  • 台州 做网站企业推广方式力荐隐迅推
  • 做家装图接单网站网站开发什么语言安全
  • 营销网站模板htlm免费个人域名邮箱
  • ps个人网站建设用angular做的网站
  • 辛集做网站手机网站建站步骤论文
  • 网站建设公司怎么盈利电脑上怎么建设网站
  • 免费建造网站wordpress显示注册用户
  • 企业自建网站营销论文怎么买wordpress主题
  • 网站建设前期分析做网站需要学什么
  • 合肥新站区有做网站的吗网页设计建设网站模板
  • 昆明做网站首选互维高校资源网网站建设方案
  • iis配置网站是什么培训机构官网
  • 做网站初中潍坊市奎文区建设局网站
  • 廊坊网站建设兼职网址域名ip查询
  • 建医疗网站步骤手机网站制作行业排行
  • 网站建设模板设计做英文网站多钱
  • 社交网站模板下载建网站的基本步骤
  • 邯郸的网站建设ps网页模板
  • 做网站的软件工程师seo全网营销
  • 浦东新区网站建设网站建设 图片压缩
  • 手机网站免费建站广东网站关键词排名