import javax.imageio.*; import java.awt.image.*; import java.awt.event.*; import java.awt.*; import java.security.NoSuchAlgorithmException; import java.security.MessageDigest; import java.lang.reflect.*; import java.net.*; import java.io.*; import javax.swing.text.*; import javax.swing.event.*; import javax.swing.*; import java.util.concurrent.*; import java.util.regex.*; import java.util.List; import java.util.zip.*; import java.util.*; public class main { static class Q { LinkedBlockingQueue q = new LinkedBlockingQueue(); Q() {} Q(String name, boolean startThread) { if (startThread) new Thread(name) { public void run() { Q.this.run(); } }.start(); } Iterable master() { return new Iterable() { public Iterator iterator() { return new Iterator() { Runnable x; public boolean hasNext() { try { //debug("hasNext"); while (x == null) x = q.poll(1, TimeUnit.DAYS); //debug("hasNext true"); return true; } catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }} public Runnable next() { //debug("next"); hasNext(); Runnable _x = x; x = null; //debug("next " + structure(x)); return _x; } public void remove() { } }; } }; } void add(Runnable r) { q.add(r); } void run() { for (Runnable r : master()) { try { r.run(); } catch (Throwable e) { e.printStackTrace(); } } } } // class Q public static void main(String[] args) throws Exception { final Q queue = new Q(); Thread _t = new Thread() { public void run() { try { queue.run(); } catch (Exception _e) { throw _e instanceof RuntimeException ? (RuntimeException) _e : new RuntimeException(_e); } } }; _t.start(); queue.add(new Runnable() { public void run() { try { print("Hello!"); } catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}}); sleep(2000); queue.add(new Runnable() { public void run() { try { print("Here we are again!"); } catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}}); } static void sleep(long ms) { try { Thread.sleep(ms); } catch (Exception e) { throw new RuntimeException(e); } } static void sleep() { try { synchronized(main.class) { main.class.wait(); } } catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }} static void print() { System.out.println(); } static void print(Object o) { System.out.println(o); } static void print(long i) { System.out.println(i); } }