import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class CallAbleTest {
public static void main(String[] args) throws InterruptedException, ExecutionException {
ExecutorService service = Executors.newFixedThreadPool(2);
MyCallAbled m1= new MyCallAbled("aa");
MyCallAbled m2= new MyCallAbled("bb");
Future future1 = service.submit(m1);
Future future2 =service.submit(m2);
System.out.println(future1.get().toString());
System.out.println(future2.get().toString());
service.shutdown();
}
static class MyCallAbled implements Callable{
private String name;
public MyCallAbled(String name){
this.name=name;
}
public MyCallAbled(){
}
@Override
public Object call() throws Exception {
return name;
}
}
}