java方法执行超时关闭
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<Boolean> future = executorService.submit(() -> method(param));
try {
//设置超时时间
boolean rst = future.get(200, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
System.out.println("执行超时!");
} catch(Exception e){
System.out.println("获取数据异常," + e.getMessage());
}finally {
executorService.shutdown();
}