static class ReliableSingleThread implements Runnable { O runnable; bool running, trigger; *(O *runnable) {} void trigger() { go(); } synchronized void go() { trigger = true; if (!running) { running = true; thread "Single Thread" { _run(); } } } public void run() { go(); } synchronized bool running() { ret running; } // use only if this is the last time you trigger this void triggerAndWait() { trigger(); while (running()) sleep(1); } void _run() { while licensed { synchronized(this) { if (!trigger) { running = false; break; } trigger = false; } pcallF(runnable); } } }