您好,登錄后才能下訂單哦!
重寫的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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。