Once { public final void ensure() { if (Thread.holdsLock(this)) { return; } if (!ran) { synchronized (this) { if (!ran) { try { run(); ran = true; } catch (Exception error) { throw Throwables.propagate(error); } } } } } @Deprecated  Once(ReadWriteLock lock);  Once(); final void ensure(); final void reset();  }
@Test public void testEnsure() throws InterruptedException { testOnce(new Once() { @Override protected void run() throws InterruptedException { Thread.sleep(1000); results.put(this, this); } }); }
@Test public void testReentrancy() throws InterruptedException { testOnce(new Once() { @Override protected void run() throws InterruptedException { ensure(); results.put(this, this); } }); }