public class Test { public static void main(String[] args) { ExecutorService executor = Executors.newSingleThreadExecutor(); FutureTask future = new FutureTask(new Callable() { public URLConnection call() throws Exception { // TODO Auto-generated…
直接上代码 import java.util.concurrent.Callable; public class MyCallable implements Callable<String> { private long waitTime; public MyCallable(int timeInMillis){ this.waitTime=timeInMillis; } @Override public String call() throws Exception { Thread.slee…
Future API: public interface Future<V> { /** * Attempts to cancel execution of this task. This attempt will * fail if the task has already completed, has already been cancelled, * or could not be cancelled for some other reason. If successful, * and…