import java.util.*; public class SetLock implements LockInvokable { private Set s; public SetLock(Set s) { this.s = s; } public void lockInvoke(Runnable r) { helper(s.iterator(), r); } private void helper(Iterator i, Runnable r) { if (i.hasNext()) { synchronized(i.next()) { helper(i, r); } } else r.run(); } }