java 利用Future做超时任务处理

Callable<String> task = new Callable<String>() {
    @Override
    public String call() throws Exception {
        return HttpRequestUtil.host().doGet(requestUrl);
    }
};
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<String> future = executorService.submit(task);
String hostInfo = future.get(10,TimeUnit.SECONDS);

  

posted @ 2018-12-05 11:02  尐鱼儿  阅读(766)  评论(0编辑  收藏  举报