publicinterfaceCallable<V> { /** * Computes a result, or throws an exception if unable to do so. * * @return computed result * @throws Exception if unable to compute a result */ V call()throws Exception; } publicinterfaceRunnable{ /** * When an object implementing interface <code>Runnable</code> is used * to create a thread, starting the thread causes the object's * <code>run</code> method to be called in that separately executing * thread. * <p> * The general contract of the method <code>run</code> is that it may * take any action whatsoever. * * @see java.lang.Thread#run() */ publicabstractvoidrun(); }
Callable中申明的方法是call(),Runnable中申明的方法是run();
Callable中的call()方法有返回值,而run()方法没有返回值;
call()方法可抛出异常,而run()方法则没有;
5.Future详解
1 2 3 4 5 6 7 8
publicinterfaceFuture<V> { booleancancel(boolean mayInterruptIfRunning); booleanisCancelled(); booleanisDone(); V get()throws InterruptedException, ExecutionException; V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException; }