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