Index: mpe/viewers/jumpshot-2/src/SwingWorker.java =================================================================== RCS file: /MPIhome/jumpshot-2.0/src/SwingWorker.java,v retrieving revision 1.1 retrieving revision 1.2 diff -r1.1 -r1.2 4,7c4,13 < * An abstract class that you subclass to perform < * GUI-related work in a dedicated thread. < * For instructions on using this class, see < * http://java.sun.com/products/jfc/swingdoc-current/threads2.html --- > * This is the 3rd version of SwingWorker (also known as > * SwingWorker 3), an abstract class that you subclass to > * perform GUI-related work in a dedicated thread. For > * instructions on using this class, see: > * > * http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html > * > * Note that the API changed slightly in the 3rd version: > * You must now invoke start() on the SwingWorker after > * creating it. 10c16 < private Object value; --- > private Object value; // see getValue(), setValue() 13a20,47 > * Class to maintain reference to current worker thread > * under separate synchronization control. > */ > private static class ThreadVar { > private Thread thread; > ThreadVar(Thread t) { thread = t; } > synchronized Thread get() { return thread; } > synchronized void clear() { thread = null; } > } > > private ThreadVar threadVar; > > /** > * Get the value produced by the worker thread, or null if it > * hasn't been constructed yet. > */ > protected synchronized Object getValue() { > return value; > } > > /** > * Set the value produced by worker thread > */ > private synchronized void setValue(Object x) { > value = x; > } > > /** 27c61 < * to force the worker to abort what it's doing. --- > * to force the worker to stop what it's doing. 30,34c64,68 < Thread t = thread; < if (t != null) { < t.interrupt(); < } < thread = null; --- > Thread t = threadVar.get(); > if (t != null) { > t.interrupt(); > } > threadVar.clear(); 38a73,76 > * Returns null if either the constructing thread or the current > * thread was interrupted before a value was produced. > * > * @return the value created by the construct method 41,47c79,82 < while (true) { // keep trying if we're interrupted < Thread t; < synchronized (SwingWorker.this) { < t = thread; < if (t == null) { < return value; < } --- > while (true) { > Thread t = threadVar.get(); > if (t == null) { > return getValue(); 52a88,89 > Thread.currentThread().interrupt(); // propagate > return null; 56a94 > 68,70c106,110 < synchronized(SwingWorker.this) { < value = construct(); < thread = null; --- > try { > setValue(construct()); > } > finally { > threadVar.clear(); 71a112 > 76,77c117,128 < thread = new Thread(doConstruct); < thread.start(); --- > Thread t = new Thread(doConstruct); > threadVar = new ThreadVar(t); > } > > /** > * Start the worker thread. > */ > public void start() { > Thread t = threadVar.get(); > if (t != null) { > t.start(); > } Index: mpe/viewers/jumpshot-2/src/Mainwin.java =================================================================== RCS file: /MPIhome/jumpshot-2.0/src/Mainwin.java,v retrieving revision 1.4 retrieving revision 1.5 diff -r1.4 -r1.5 458a459 > readWorker.start(); 475c476,479 < if (reader_alive) {readWorker.interrupt (); readWorker = null;} --- > if (readWorker != null && reader_alive) { > readWorker.interrupt (); > readWorker = null; > } Index: mpe/viewers/jumpshot-3/src/main/FrameReadingTask.java =================================================================== RCS file: /MPIhome/jumpshot-3/src/main/FrameReadingTask.java,v retrieving revision 1.2 retrieving revision 1.3 diff -r1.2 -r1.3 55a56 > read_worker.start(); Index: mpe/viewers/jumpshot-3/src/main/Mainwin.java =================================================================== RCS file: /MPIhome/jumpshot-3/src/main/Mainwin.java,v retrieving revision 1.3 retrieving revision 1.4 diff -r1.3 -r1.4 451c451 < c = c.getSuperclass(); --- > c = c.getSuperclass(); 569a570,573 > // Start the readWorker thread after the thread has been created. > // It is done to avoid race condition in SwingWorker2. > readWorker.start(); > 616c620 < if ( reader_alive ) { --- > if ( readWorker != null && reader_alive ) { Index: mpe/viewers/jumpshot-3/src/main/SwingWorker.java =================================================================== RCS file: /MPIhome/jumpshot-3/src/main/SwingWorker.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -r1.1.1.1 -r1.2 1,2c1 < //import com.sun.java.swing.SwingUtilities; //old package name < import javax.swing.SwingUtilities; //new package name --- > import javax.swing.SwingUtilities; 5,8c4,13 < * An abstract class that you subclass to perform < * GUI-related work in a dedicated thread. < * For instructions on using this class, see < * http://java.sun.com/products/jfc/swingdoc-current/threads2.html --- > * This is the 3rd version of SwingWorker (also known as > * SwingWorker 3), an abstract class that you subclass to > * perform GUI-related work in a dedicated thread. For > * instructions on using this class, see: > * > * http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html > * > * Note that the API changed slightly in the 3rd version: > * You must now invoke start() on the SwingWorker after > * creating it. 56c61 < * to force the worker to abort what it's doing. --- > * to force the worker to stop what it's doing. 68,69c73,74 < * Returns null if either the constructing thread or < * the current thread was interrupted before a value was produced. --- > * Returns null if either the constructing thread or the current > * thread was interrupted before a value was produced. 114c119,128 < t.start(); --- > } > > /** > * Start the worker thread. > */ > public void start() { > Thread t = threadVar.get(); > if (t != null) { > t.start(); > }