Esempio n. 1
0
 /**
  * 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();
 }
Esempio n. 2
0
 /**
  * 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;
     }
   }
 }
Esempio n. 3
0
 /** Start the worker thread. */
 public void start() {
   Thread t = threadVar.get();
   if (t != null) {
     t.start();
   }
 }
Esempio n. 4
0
 /** Allows the priority of the worker thread to be set. */
 public void setPriority(int priority) {
   threadVar.get().setPriority(priority);
 }