public class IteratorHelper { T _v; boolean _isValueSet = false; Thread _t; public IteratorHelper (Runnable r) { _t = new Thread(r); start(); } public void start() { _t.start(); } public void yield(T v) { _v=v; _isValueSet = true; Thread.yield(); } public synchronized T get () { if(!_isValueSet) { try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } } _isValueSet = false; notify(); return _v; } public boolean done() { return _isValueSet; } }