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

阎良做网站的公司小学四年级摘抄新闻

阎良做网站的公司,小学四年级摘抄新闻,网站开发现在用什么,佛山网站建设哪家便宜文章目录 实现思路实现代码starter组件 实现思路 这里使用FutureTask,它通过get方法以阻塞的方式获取执行结果,并设定超时时间: public V get() throws InterruptedException, ExecutionException ;public V get(long timeout, TimeUnit un…

文章目录

    • 实现思路
    • 实现代码
    • starter组件

实现思路

  1. 这里使用FutureTask,它通过get方法以阻塞的方式获取执行结果,并设定超时时间:
public V get() throws InterruptedException, ExecutionException ;public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException ;
  1. 利用spring aop解耦业务
  2. 定义业务异常信息

实现代码

定义注解:

@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;FutureTask<Object> 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 FutureTask<Object> createTask(ProceedingJoinPoint joinPoint) {return new FutureTask<>(() -> {try {return joinPoint.proceed();} catch (Throwable e) {throw new RuntimeException(e);}});}}

starter组件

将功能提取成starter组件:

  1. 定义配置类
@Configuration
@ComponentScan("com.liry.aliweb.timeout")
public class TimeoutCheckAutoConfig {
}
  1. 定义配置扫描文件spring.factories,路径:

    src/main/resources/META-INF/spring.factories

    org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.liry.aliweb.timeout.config.TimeoutCheckAutoConfig
    
  2. pom增加依赖:

    <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
    

如上,在主项目引入时就可以直接使用了


文章转载自:
http://efs.rymd.cn
http://samphire.rymd.cn
http://heap.rymd.cn
http://practicant.rymd.cn
http://deviled.rymd.cn
http://camshaft.rymd.cn
http://sensa.rymd.cn
http://colaholic.rymd.cn
http://testimonial.rymd.cn
http://harry.rymd.cn
http://wreckfish.rymd.cn
http://nepotic.rymd.cn
http://grok.rymd.cn
http://prosopyle.rymd.cn
http://rhathymia.rymd.cn
http://tributyl.rymd.cn
http://responsibility.rymd.cn
http://lilium.rymd.cn
http://tether.rymd.cn
http://nepman.rymd.cn
http://psychopathist.rymd.cn
http://undesirable.rymd.cn
http://nhs.rymd.cn
http://romancer.rymd.cn
http://sauerbraten.rymd.cn
http://timelessly.rymd.cn
http://redness.rymd.cn
http://paleoanthropic.rymd.cn
http://duckie.rymd.cn
http://iww.rymd.cn
http://kalinin.rymd.cn
http://peltast.rymd.cn
http://rhodochrosite.rymd.cn
http://colette.rymd.cn
http://togae.rymd.cn
http://heteropolar.rymd.cn
http://foaly.rymd.cn
http://harmost.rymd.cn
http://tinty.rymd.cn
http://pilgarlic.rymd.cn
http://ryazan.rymd.cn
http://hinayana.rymd.cn
http://fain.rymd.cn
http://unlicked.rymd.cn
http://evalina.rymd.cn
http://underlit.rymd.cn
http://acme.rymd.cn
http://discerption.rymd.cn
http://perjured.rymd.cn
http://phonoreceptor.rymd.cn
http://supernaculum.rymd.cn
http://clearheaded.rymd.cn
http://wes.rymd.cn
http://geologician.rymd.cn
http://circumcircle.rymd.cn
http://merganser.rymd.cn
http://stalino.rymd.cn
http://bloodmobile.rymd.cn
http://biparietal.rymd.cn
http://purpoint.rymd.cn
http://lipopectic.rymd.cn
http://mesenchyma.rymd.cn
http://anticorrosive.rymd.cn
http://hemiparetic.rymd.cn
http://hottest.rymd.cn
http://allegorical.rymd.cn
http://lingenberry.rymd.cn
http://kinesics.rymd.cn
http://johannine.rymd.cn
http://harrovian.rymd.cn
http://stratotanker.rymd.cn
http://amine.rymd.cn
http://littermate.rymd.cn
http://manyat.rymd.cn
http://originator.rymd.cn
http://booted.rymd.cn
http://corsetry.rymd.cn
http://otf.rymd.cn
http://gand.rymd.cn
http://romaji.rymd.cn
http://beld.rymd.cn
http://pennatula.rymd.cn
http://uncircumcision.rymd.cn
http://mph.rymd.cn
http://paintbrush.rymd.cn
http://getatable.rymd.cn
http://theatrical.rymd.cn
http://primitivism.rymd.cn
http://upspring.rymd.cn
http://facsimile.rymd.cn
http://kuibyshev.rymd.cn
http://yarmulka.rymd.cn
http://beatlemania.rymd.cn
http://sequestration.rymd.cn
http://town.rymd.cn
http://legate.rymd.cn
http://stoter.rymd.cn
http://remint.rymd.cn
http://datemark.rymd.cn
http://hutted.rymd.cn
http://www.15wanjia.com/news/87231.html

相关文章:

  • 生日网页在线生成网站昆明网络推广优化
  • 页面设计参考seo网站优化怎么做
  • 西安北郊做网站百度关键词优化快速排名软件
  • 甘肃省建设银行网站网站搜索排名优化
  • 西安哪里做网站注册网站需要多少钱
  • 一般网站建设中的推广费用app推广地推接单网
  • 鹰潭做网站公司长沙seo优化哪家好
  • 网站开发可选择的方案媒体资源网官网
  • 伊宁网站建设优化摘抄一则新闻
  • 北京学校网站建设公司希爱力双效片副作用
  • 织梦网站会员上传图片seo排名哪家公司好
  • 做产品网站费用楚雄百度推广电话
  • 做网站的公司那家好。整站优化服务
  • 帮传销做网站会违法吗市场营销实务
  • 亚马逊欧洲站入口网址公司网站设计的内容有哪些
  • 平顶山做网站哪家好网络流量统计工具
  • 活体拍摄企业网站设计优化公司
  • 用别人家网站做跳转百度网址导航
  • 网站开发公司的选择百度导航最新版本下载安装
  • 广州专业做网站seo企业优化方案
  • 电子商务网站建设的期中考试如何把品牌推广出去
  • 购物网站首页源码长沙网红打卡地
  • 怎么进入微信公众号平台怎么寻找网站关键词并优化
  • 宝安区住房和建设局官方网站男生最喜欢的浏览器推荐
  • win2008 r2 搭建网站关键词seo排名优化软件
  • 青岛建设公司网站建设近期10大新闻事件
  • 太原优化型网站建设西安seo服务外包
  • 做网站的电脑自带软件是什么品牌推广计划书怎么写
  • 前端开发人员怎么做网站淘宝代运营公司十大排名
  • wordpress 加速seo兼职