/** * A new method that interrupts the worker thread. Call this method to force the worker to stop * what it's doing. */ public void interrupt() { Thread t = threadVar.get(); if (t != null) { t.interrupt(); } threadVar.clear(); }
/** * Return the value created by the <code>construct</code> method. Returns null if either the * constructing thread or the current thread was interrupted before a value was produced. * * @return the value created by the <code>construct</code> method */ public Object get() { while (true) { Thread t = threadVar.get(); if (t == null) { return getValue(); } try { t.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // propagate return null; } } }
/** Start the worker thread. */ public void start() { Thread t = threadVar.get(); if (t != null) { t.start(); } }
/** Allows the priority of the worker thread to be set. */ public void setPriority(int priority) { threadVar.get().setPriority(priority); }