java並發包之Callable
阿新 • • 發佈:2018-05-22
並且 ride color pub pre util main call() ati
Callable和Runnable的差異
Callable接口類似於Runnable,但是Runnable不會返回結果,並且無法拋出返回結果的異常,而Callable可以
package com.wjz.demo; import java.util.concurrent.Callable; public class CallableDemo { public static void main(String[] args) { try { Callable<String> call = new Callable<String>() { @Overridepublic String call() throws Exception { return "hello world!"; } }; System.out.println(call.call()); Runnable run = new Runnable() { @Override public void run() { System.out.println("hello world!"); } }; run.run(); } catch (Exception e) { // } } }
java並發包之Callable