重写的call方法可以有返回值,可以抛出异常
public class ThreadDownload implements Callable<Boolean> {
public Boolean call() throws Exception
{
return true;
}
public static void main(String[]args) throws InterruptedException, ExecutionException
{
ThreadDownload a=new ThreadDownload();
ThreadDownload b=new ThreadDownload();
ThreadDownload c=new ThreadDownload();
//创建执行服务
ExecutorService ser =Executors.newFixedThreadPool(3);
//提交执行
Future<Boolean>result1=ser.submit(a);
Future<Boolean>result2=ser.submit(b);
Future<Boolean>result3=ser.submit(c);
//获取结果
boolean r1=result1.get();
boolean r2=result2.get();
boolean r3=result3.get();
//关闭服务:
ser.shutdownNow();
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。