org.tentackle.ui
Class WorkerThread

java.lang.Object
  extended by java.lang.Thread
      extended by org.tentackle.ui.WorkerThread
All Implemented Interfaces:
Runnable

public class WorkerThread
extends Thread

A worker thread.

The thread will dispose a dialog if terminated.

The specified Runnable must either monitor whether the thread got interrupt()ed by checking Thread.isInterrupted() or override Thread.interrupt() and terminate the thread gracefully.

Author:
harald
See Also:
WorkerDialog

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WorkerThread(Runnable todo, boolean modal, String title)
          Creates a worker thread using an WorkerDialog.
WorkerThread(Runnable todo, boolean modal, String title, JDialog workerDialog)
          Creates a worker thread.
WorkerThread(Runnable todo, String title)
          Creates a worker thread using a modal WorkerDialog and a given title.
This is the default case.
 
Method Summary
 JDialog getWorkerDialog()
          Gets the worker dialog.
 void run()
          If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
 void start()
          Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
 void startAndWait()
          Starts the workerthread and waits until the modal worker dialog is closed.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WorkerThread

public WorkerThread(Runnable todo,
                    boolean modal,
                    String title,
                    JDialog workerDialog)
Creates a worker thread.

Parameters:
todo - the runnable for this thread
modal - true if dialog should be set to modal
title - the dialog's title, null if leave unchanged
workerDialog - the dialog that will be disposed when thread terminates, null if WorkerDialog

WorkerThread

public WorkerThread(Runnable todo,
                    boolean modal,
                    String title)
Creates a worker thread using an WorkerDialog.

Parameters:
todo - what's to do in the run-method?
modal - true if dialog should be set to modal
title - the dialog's title, null if leave unchanged

WorkerThread

public WorkerThread(Runnable todo,
                    String title)
Creates a worker thread using a modal WorkerDialog and a given title.
This is the default case.

Parameters:
todo - what's to do in the run-method?
title - the dialog's title, null if leave unchanged
Method Detail

getWorkerDialog

public JDialog getWorkerDialog()
Gets the worker dialog.

Returns:
the worker dialog (usually a WorkerDialog)

run

public void run()
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.

Subclasses of Thread should override this method.

Overridden to dispose the dialog.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
See Also:
Thread.start(), Thread.stop(), Thread.Thread(ThreadGroup, Runnable, String)

start

public void start()
Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

The result is that two threads are running concurrently: the current thread (which returns from the call to the start method) and the other thread (which executes its run method).

It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.

Overridden to show the dialog. The dialog will be shown by invokeLater. This allows the method to return immediately even if the dialog is modal.

Overrides:
start in class Thread
See Also:
Thread.run(), Thread.stop()

startAndWait

public void startAndWait()
Starts the workerthread and waits until the modal worker dialog is closed.



Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de