| java.lang.Object uk.co.whisperingwind.framework.SwingThread
SwingThread | abstract public class SwingThread (Code) | | Inspired by, but not to identical to SwingWorker on Sun's
web site. Runs one part, construct in a separate
thread, then finished in the event dispatch thread.
The construct method should not modify any Swing
components as these are not thread safe. finished
can safely modify Swing components as it is run in the event
thread. finished does not run until
construct is complete.
When they say Swing is not Thread safe, they really mean it.
For example, poping up a dialog using JOptionPane from some thread
other than event dispatch can hang the application. Modifying the
TableModel in use for a visible JTable is really asking for it.
|
Field Summary | |
protected boolean | stopped |
Constructor Summary | |
public | SwingThread() Create a SwingThread. |
Method Summary | |
abstract public void | construct() The sub class must implement this method. | abstract public void | finished() The sub class must implement this method. | public void | interrupt() This doesn't actually interrupt the thread. | public synchronized boolean | isInterrupted() Returns true if the thread has been interrupted. | public void | start() Start the helper thread. |
stopped | protected boolean stopped(Code) | | |
SwingThread | public SwingThread()(Code) | | Create a SwingThread. Call start to start the
thread.
|
construct | abstract public void construct()(Code) | | The sub class must implement this method. It is run in a
separate thread and must not modify any Swing component.
|
finished | abstract public void finished()(Code) | | The sub class must implement this method. It is run in the
event dispatch thread when construct is complete.
|
interrupt | public void interrupt()(Code) | | This doesn't actually interrupt the thread. This class is used
for methods which communicate with the database server. Some
JDBC drivers (eg Oracle) don't like being interrupted and will
fail in subsequent calls if they are. This relies on construct
taking notice of the value of "stopped". Will not return
until the helper thread finishes.
|
isInterrupted | public synchronized boolean isInterrupted()(Code) | | Returns true if the thread has been interrupted. The thread may
not have yet completed.
|
start | public void start()(Code) | | Start the helper thread. This will call construct
and, when the thread completes, finished .
|
|
|