Class CloseableMonitor (1.7.1)

public class CloseableMonitor

Wraps a Monitor with methods that can be used with try-with-resources.

Inheritance

java.lang.Object > CloseableMonitor

Constructors

CloseableMonitor()

public CloseableMonitor()

Fields

monitor

public final Monitor monitor
Field Value
TypeDescription
com.google.common.util.concurrent.Monitor

Methods

enter()

public CloseableMonitor.Hold enter()

try-with-resources wrapper for enter. For example...


 try (CloseableMonitor.Hold h = monitor.enter()) {
   // Do stuff
 }
 // Monitor is automatically released
 
Returns
TypeDescription
CloseableMonitor.Hold

enterWhenUninterruptibly(Monitor.Guard condition)

public CloseableMonitor.Hold enterWhenUninterruptibly(Monitor.Guard condition)

try-with-resources wrapper for enterWhenUninterruptibly. For example:

final Monitor.Guard guard = new Monitor.Guard(monitor.monitor) { @Override public boolean isSatisfied() { assertThat(monitor.monitor.isOccupied()).isTrue(); return state; } };

try (CloseableMonitor.Hold h = monitor.enterWhenUninterruptibly(guard)) { // Do stuff } // Monitor is automatically released

Parameter
NameDescription
conditioncom.google.common.util.concurrent.Monitor.Guard
Returns
TypeDescription
CloseableMonitor.Hold