    001    package escjava.gui;
    002
    003    import java.util.LinkedList;
    004
    005    public class WindowTasks implements Runnable {
    006
    007            public void run() {
    008
    009                while (true) {
    010                    Object o = getTask();
    011                    if (o == null) { Thread.currentThread().yield(); continue; }
    012                    // Do something with task
    013
    014                }
    015
    016            }
    017
    018        static private /*@non_null*/ LinkedList tasks = new LinkedList();
    019
    020            synchronized static public void addTask(Object o) {
    021                    tasks.addLast(o);
    022            }
    023
    024            synchronized static private Object getTask() {
    025                    if (tasks.isEmpty()) return null;
    026                    return tasks.removeFirst();
    027            }
    028
    029    }