public class CloseableMonitor extends Object
| Modifier and Type | Class and Description |
|---|---|
class |
CloseableMonitor.Hold
This is meant for use in the try-with-resources pattern.
|
| Modifier and Type | Field and Description |
|---|---|
com.google.common.util.concurrent.Monitor |
monitor |
| Constructor and Description |
|---|
CloseableMonitor() |
| Modifier and Type | Method and Description |
|---|---|
CloseableMonitor.Hold |
enter()
try-with-resources wrapper for enter.
|
CloseableMonitor.Hold |
enterWhenUninterruptibly(com.google.common.util.concurrent.Monitor.Guard condition)
try-with-resources wrapper for enterWhenUninterruptibly.
|
public CloseableMonitor.Hold enterWhenUninterruptibly(com.google.common.util.concurrent.Monitor.Guard condition)
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
public CloseableMonitor.Hold enter()
try (CloseableMonitor.Hold h = monitor.enter) {
// Do stuff
}
// Monitor is automatically released
Copyright © 2020 Google LLC. All rights reserved.