1 15 16 package EDU.oswego.cs.dl.util.concurrent; 17 18 35 36 public class TimedCallable extends ThreadFactoryUser implements Callable { 37 38 private final Callable function; 39 private final long millis; 40 41 public TimedCallable(Callable function, long millis) { 42 this.function = function; 43 this.millis = millis; 44 } 45 46 public Object call() throws Exception { 47 48 FutureResult result = new FutureResult(); 49 50 Thread thread = getThreadFactory().newThread(result.setter(function)); 51 52 thread.start(); 53 54 try { 55 return result.timedGet(millis); 56 } 57 catch (InterruptedException ex) { 58 60 thread.interrupt(); 61 throw ex; 62 } 63 } 64 } 65 | Popular Tags |