1 31 32 package org.apache.commons.httpclient.util; 33 34 43 44 public final class TimeoutController { 45 46 49 private TimeoutController() { 50 } 51 52 62 public static void execute(Thread task, long timeout) throws TimeoutException { 63 task.start(); 64 try { 65 task.join(timeout); 66 } catch (InterruptedException e) { 67 68 } 69 if (task.isAlive()) { 70 task.interrupt(); 71 throw new TimeoutException(); 72 } 73 } 74 75 81 public static void execute(Runnable task, long timeout) throws TimeoutException { 82 Thread t = new Thread (task, "Timeout guard"); 83 t.setDaemon(true); 84 execute(t, timeout); 85 } 86 87 90 public static class TimeoutException extends Exception { 91 92 public TimeoutException() { 93 } 94 } 95 } 96 | Popular Tags |