foxtrot
Class AsyncWorker

java.lang.Object
  extended by foxtrot.AsyncWorker

public class AsyncWorker
extends Object

The class that executes asynchronous tasks.
This class is used when asynchronous task processing is needed, while 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 } } }); } });

Version:
$Revision: 255 $

Method Summary
static WorkerThread getWorkerThread()
           
static void post(AsyncTask task)
          Executes asynchronously the given AsyncTask in a worker thread.
static void setWorkerThread(WorkerThread workerThread)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getWorkerThread

public static WorkerThread getWorkerThread()
See Also:
Worker.getWorkerThread()

setWorkerThread

public static void setWorkerThread(WorkerThread workerThread)
See Also:
Worker.setWorkerThread(foxtrot.WorkerThread)

post

public static void post(AsyncTask task)
Executes asynchronously the given AsyncTask in a worker thread.
This method returns immediately; when the AsyncTask is finished, its AsyncTask.finish() method will be called in the Event Dispatch Thread.

Parameters:
task -


Copyright © 2011 KnowledgePlaza. All Rights Reserved.