-
java方法执行超时关闭
- Callable<String> task = new Callable<String>() {
- @Override
- public String call() throws Exception{
- //执行耗时代码
- Thread.sleep(10000);
- return "success";
- }
- };
- ExecutorService executorService = Executors.newSingleThreadExecutor();
- Future<String> future = executorService.submit(task);
- try {
- //设置超时时间
- String rst = future.get(5,TimeUnit.SECONDS);
- System.out.println(rst);
- } catch (TimeoutException e) {
- System.out.println("执行超时");
- } catch(Exception e){
- System.out.println("获取数据异常," + e.getMessage());
- }finally {
- executorService.shutdown();
- }
-
相关阅读:
js自动小轮播
js字符串
工资
可是姑娘,你为什么要编程呢?
程序猿媳妇儿注意事项
js勾选时显示相应内容
js点击显示隐藏
js选项卡
js数组
js旋转V字俄罗斯方块
-
原文地址:https://www.cnblogs.com/min-yu/p/10927535.html
Copyright © 2020-2023
润新知