1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public class CallableTest {
public static void main(String[] args) throws ExecutionException, InterruptedException { MyThread thread = new MyThread(); FutureTask futureTask = new FutureTask(thread);
new Thread(futureTask, "A").start(); new Thread(futureTask, "B").start();
Integer s = (Integer) futureTask.get(); System.out.println(s); } }
class MyThread implements Callable<Integer> {
@Override public Integer call() throws Exception { System.out.println("call()"); return 1024; } }
|