1. 程式人生 > >Callable介面與Runnable介面的區別

Callable介面與Runnable介面的區別

public class ThreadTestB {
 public static void main(String[] args) {
  ExecutorService e=Executors.newFixedThreadPool(10);
  Future f1=e.submit(new MyCallableA());
  Future f2=e.submit(new MyCallableA());
  Future f3=e.submit(new MyCallableA());
  Future f4=e.submit(new MyCallableA());
  Future f5=e.submit(new MyCallableA());
  System.out.println("--Future.get()....");
  try {
   System.out.println(f1.get());
   System.out.println(f2.get());
   System.out.println(f3.get());
   System.out.println(f4.get());
   System.out.println(f5.get());
  } catch (InterruptedException e1) {
   e1.printStackTrace();
  } catch (ExecutionException e1) {
   e1.printStackTrace();
  }
  
  e.shutdown();
  
 }