1 8 9 package foxtrot; 10 11 import javax.swing.SwingUtilities ; 12 13 import foxtrot.workers.MultiWorkerThread; 14 15 59 public class AsyncWorker extends AbstractWorker 60 { 61 private static AsyncWorker instance = new AsyncWorker(); 62 63 66 private AsyncWorker() 67 { 68 } 69 70 73 public static WorkerThread getWorkerThread() 74 { 75 return instance.workerThread(); 76 } 77 78 81 public static void setWorkerThread(WorkerThread workerThread) 82 { 83 instance.workerThread(workerThread); 84 } 85 86 89 WorkerThread createDefaultWorkerThread() 90 { 91 return new MultiWorkerThread(); 92 } 93 94 102 public static void post(AsyncTask task) 103 { 104 instance.post(task, getWorkerThread()); 105 } 106 107 private void post(AsyncTask task, WorkerThread workerThread) 108 { 109 boolean isEventThread = SwingUtilities.isEventDispatchThread(); 110 if (!isEventThread) 111 { 112 throw new IllegalStateException ("AsyncWorker.post() can be called only from the AWT Event Dispatch Thread"); 113 } 114 workerThread.postTask(task); 115 } 116 } 117 | Popular Tags |