1 /** 2 * Copyright (c) 2002-2005, Simone Bordet 3 * All rights reserved. 4 * 5 * This software is distributable under the BSD license. 6 * See the terms of the BSD license in the documentation provided with this software. 7 */ 8 9 package foxtrot; 10 11 /** 12 * Implementations of this interface run 13 * {@link Task}s in a thread that is not the Event Dispatch Thread. <br /> 14 * Implementations should extend {@link AbstractWorkerThread}. 15 * @version $Revision: 1.8 $ 16 */ 17 public interface WorkerThread 18 { 19 /** 20 * Starts this WorkerThread, responsible for running {@link Task}s (not in the 21 * Event Dispatch Thread). 22 * Applets can stop threads used by implementations of this WorkerThread in any moment, 23 * and this method also can be used to restart this WorkerThread 24 * if it results that it is not alive anymore. 25 * @see #isAlive 26 */ 27 public void start(); 28 29 /** 30 * Returns whether this WorkerThread is alive. It is not enough to return 31 * whether this WorkerThread has been started, because Applets can stop threads 32 * used by implementations of this WorkerThread in any moment. 33 * If this WorkerThread is not alive, it must be restarted. 34 * @see #start 35 */ 36 public boolean isAlive(); 37 38 /** 39 * Returns whether the current thread is a thread used by the implementation of 40 * this WorkerThread to run {@link Task}s. 41 */ 42 public boolean isWorkerThread(); 43 44 /** 45 * Posts a Task to be run by this WorkerThread in a thread that is not the 46 * Event Dispatch Thread. This method must be called from the 47 * Event Dispatch Thread and should return immediately. 48 * Implementations should check if this WorkerThread {@link #isAlive} to guarantee 49 * that the posted Task will be executed by this WorkerThread. 50 * @see #runTask 51 */ 52 public void postTask(Task task); 53 54 /** 55 * Runs the given Task. This method must be called by a thread that is not the 56 * Event Dispatch Thread, and must execute the task in the same thread of the 57 * caller, synchronously. 58 * @see #postTask 59 */ 60 public void runTask(Task task); 61 } 62