cshannon commented on code in PR #5338:
URL: https://github.com/apache/accumulo/pull/5338#discussion_r1956802654
##########
core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java:
##########
@@ -484,13 +484,18 @@ protected void copyStats(ZcStat userStat, ZcStat
cachedStat) {
* Clears this cache.
*/
protected void clear() {
- Preconditions.checkState(!closed);
+ if (closed) {
+ return;
+ }
nodeCache.clear();
updateCount.incrementAndGet();
log.trace("{} cleared all from cache", cacheId);
}
public void close() {
+ if (closed) {
Review Comment:
Changes here are fine, but I was wondering if it would be better to use a
final AtomicBoolean for the closed flag instead of a volatile. The atomic
classes are really nice for use cases like this. You could then do something
like:
```java
public void close() {
if (closed.compareAndSet(false, true)) {
clear();
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]