重寫的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();
//創(chuàng)建執(zhí)行服務(wù)
ExecutorService ser =Executors.newFixedThreadPool(3);
//提交執(zhí)行
Future<Boolean>result1=ser.submit(a);
Future<Boolean>result2=ser.submit(b);
Future<Boolean>result3=ser.submit(c);
//獲取結(jié)果
boolean r1=result1.get();
boolean r2=result2.get();
boolean r3=result3.get();
//關(guān)閉服務(wù):
ser.shutdownNow();
}
}
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動(dòng)態(tài)BGP最優(yōu)骨干路由自動(dòng)選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動(dòng)現(xiàn)已開啟,新人活動(dòng)云服務(wù)器買多久送多久。
當(dāng)前標(biāo)題:java多線程-實(shí)現(xiàn)Callable接口-創(chuàng)新互聯(lián)
文章URL:http://chinadenli.net/article48/ccghhp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、網(wǎng)站策劃、商城網(wǎng)站、用戶體驗(yàn)、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容