public class AsyncWorker extends Object
asynchronous tasks. Worker
is normally used for synchronous task processing.
This class offers a functionality similar to what provided by
Sun's SwingWorker
.
Example usage:
final JButton button = new JButton("Send a message !");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
AsyncWorker.post(new AsyncTask()
{
public Object run() throws Exception
{
// Send some long message
Thread.sleep(10000);
return null;
}
public void finish()
{
// Check to see if there are exceptions
// by calling getResultOrThrow()
try
{
getResultOrThrow();
button.setText("Message sent !");
}
catch (Exception x)
{
// Report exception to the user, or just log it
}
}
});
}
});
| Modifier and Type | Method and Description |
|---|---|
static WorkerThread |
getWorkerThread() |
static void |
post(AsyncTask task)
Executes asynchronously the given AsyncTask in a worker thread.
|
static void |
setWorkerThread(WorkerThread workerThread) |
public static WorkerThread getWorkerThread()
Worker.getWorkerThread()public static void setWorkerThread(WorkerThread workerThread)
public static void post(AsyncTask task)
AsyncTask.finish() method will be called in the Event Dispatch
Thread.task - Copyright © 2002-2011. All Rights Reserved.