@SuppressWarnings("unchecked")
public class CallAbleTest {
public static void main(String[] args) throws InterruptedException, ExecutionException {
CTest c1 = new CTest("a");
CTest c2 = new CTest("b");
ExecutorService e = Executors.newFixedThreadPool(2);
Future<String> f1 = e.submit(c1);
Future<String> f2 = e.submit(c2);
System.out.println(f1.get());
System.out.println(f2.get());
e.shutdown();
}
public static class CTest implements Callable{
private String name;
public CTest(String name) {
this.name = name;
}
public Object call() throws Exception {
return name+"返回值";
}
}
}