PCI和PCle子系統(tǒng)\/--》ccys1473
**
?* 實現(xiàn)Callable接口
?*/
public class Demo6_CreateCallable implements Callable<Boolean> {
? ? private String url;//網(wǎng)絡(luò)圖片地址
? ? private String name;//報錯扥文件名
? ? //有參構(gòu)造
? ? public Demo6_CreateCallable(String url, String name) {
? ? ? ? this.url = url;
? ? ? ? this.name = name;
? ? }
? ? //下載圖片線程的執(zhí)行體
? ? public Boolean call() throws Exception {
? ? ? ? WebDownloader webDownloader = new WebDownloader();
? ? ? ? webDownloader.downloader(url, name);
? ? ? ? System.out.println("下載了文件名為:" + name);
? ? ? ? return true;
? ? }
? ? public static void main(String[] args) throws ExecutionException, InterruptedException {
? ? ? ? Demo6_CreateCallable c = new Demo6_CreateCallable("https://img-home.csdnimg.cn/images/20201124032511.png", "1.png");
? ? ? ? Demo6_CreateCallable c1 = new Demo6_CreateCallable("https://img-home.csdnimg.cn/images/20201124032511.png", "2.png");
? ? ? ? Demo6_CreateCallable c2 = new Demo6_CreateCallable("https://img-home.csdnimg.cn/images/20201124032511.png", "3.png");
? ? ? ? //創(chuàng)建執(zhí)行服務(wù)
? ? ? ? ExecutorService ser = Executors.newFixedThreadPool(3);
? ? ? ? //提交執(zhí)行
? ? ? ? Future<Boolean> r = ser.submit(c);
? ? ? ? Future<Boolean> r1 = ser.submit(c1);
? ? ? ? Future<Boolean> r2 = ser.submit(c2);
? ? ? ? //獲取結(jié)果
? ? ? ? boolean res = r.get();
? ? ? ? boolean res1 = r1.get();
? ? ? ? boolean res2 = r2.get();
? ? ? ? //關(guān)閉服務(wù)
? ? ? ? ser.shutdownNow();
? ? }
}