1 37 package net.sourceforge.cruisecontrol.util.threadpool; 38 39 45 46 public class IdleThreadQueueClient implements WorkerThread { 47 private static final int ONE_SECOND = 1000; 48 private static final int TENTH_OF_SECOND = 100; 49 50 private final String name; 51 private Object result = null; 52 private boolean terminate = false; 53 private Object mutex = new Object (); 54 55 public IdleThreadQueueClient(String name) { 56 this.name = name; 57 } 58 59 public void run() { 60 int time = 0; 61 62 while (time < ONE_SECOND) { 63 synchronized (mutex) { 64 try { 65 mutex.wait(TENTH_OF_SECOND); 66 } catch (InterruptedException e) { 67 } 68 } 69 time += TENTH_OF_SECOND; 70 if (terminate) { 71 break; 72 } 73 } 74 result = "DONE WITH " + name; 75 } 76 77 public Object getResult() { 78 return result; 80 } 81 82 public void terminate() { 83 terminate = true; 84 synchronized (mutex) { 85 mutex.notifyAll(); 86 } 87 return; 88 } 89 90 public String getName() { 91 return name; 92 } 93 94 public void setName(String newName) { 95 throw new IllegalStateException ("should not be called during tests"); 96 } 97 98 } 99 | Popular Tags |