先看一段代码
import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; class ThreadA extends Thread { @Override public void run() { System.out.println("继承自Thread类的ThreadA"); } } class ThreadB implements Runnable { @Override public void run() { // TODO Auto-generated method stub System.out.println("实现Runnable接口的ThreadB"); } } class ThreadC implements Callable<String> { @Override public String call() throws Exception { // TODO Auto-generated method stub return "实现类Callable接口的ThreadC"; } } public class CreateThread { public static void main(String[] args) { new Thread(new ThreadA()).start(); new Thread(new ThreadB()).start(); ThreadC threadC = new ThreadC(); FutureTask<String> futureTask = new FutureTask<String>(threadC) ; new Thread(futureTask).start(); try { System.out.println(futureTask.get()); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
待编辑