public class CloseableMonitor
Wraps a Monitor with methods that can be used with try-with-resources.
Constructors
CloseableMonitor()
public CloseableMonitor()
Fields
monitor
public final Monitor monitor
Field Value | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
condition | com.google.common.util.concurrent.Monitor.Guard |
Returns | |
---|---|
Type | Description |
CloseableMonitor.Hold |