标签:call public except catch submit err tor ice cat
使用Callable接口可以方便的获取任务执行结果。
ExecutorService executorService = Executors.newFixedThreadPool(2); Future<Integer> future = executorService.submit( new Callable(){ @Override public Integer call() throws Exception { return 1; } }); try { int ret = future.get(); System.out.println("return:" + ret); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); }
任务成功执行完成后,Future接口的get()方法返回,并取得Callable实现类的call()方法的返回值。
return:1
标签:call public except catch submit err tor ice cat
原文地址:http://www.cnblogs.com/coe2coe/p/6613475.html