标签:return lis ... java print 处理 Fix call except
public void getcd() {
logger.info("任务开始!-------------------------------------");
final ExecutorService exec = Executors.newFixedThreadPool(1);
Callable<String> call = new Callable<String>() {
public String call() throws Exception {
Thread.sleep(2000);
return "线程执行完成.";
}
};
try {
Future<String> future = exec.submit(call);
String obj = future.get(1000, TimeUnit.MILLISECONDS); //1 秒
logger.info("任务成功返回:" + obj);
} catch (TimeoutException ex) {
logger.info("线程处理超时啦....");
ex.printStackTrace();
} catch (Exception e) {
logger.info("线程处理失败.");
e.printStackTrace();
}
logger.info("任务结束!-------------------------------------");
}
标签:return lis ... java print 处理 Fix call except
原文地址:https://www.cnblogs.com/lixxx/p/9765359.html