mirror of
https://github.com/google/nomulus.git
synced 2025-05-21 19:59:34 +02:00
Add lock.unlock() to finally clause in Counter
It is good practice to unlock a lock in a finally clause. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=132302413
This commit is contained in:
parent
dcb189943b
commit
93bf68039b
1 changed files with 9 additions and 9 deletions
|
@ -23,7 +23,6 @@ import com.google.common.util.concurrent.AtomicLongMap;
|
||||||
import com.google.common.util.concurrent.Striped;
|
import com.google.common.util.concurrent.Striped;
|
||||||
import google.registry.monitoring.metrics.MetricSchema.Kind;
|
import google.registry.monitoring.metrics.MetricSchema.Kind;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
@ -171,18 +170,19 @@ public final class Counter extends AbstractMetric<Long>
|
||||||
final void reset(Instant startTimestamp) {
|
final void reset(Instant startTimestamp) {
|
||||||
// Lock the entire set of values so that all existing values will have a consistent timestamp
|
// Lock the entire set of values so that all existing values will have a consistent timestamp
|
||||||
// after this call, without the possibility of interleaving with another reset() call.
|
// after this call, without the possibility of interleaving with another reset() call.
|
||||||
Set<ImmutableList<String>> keys = values.asMap().keySet();
|
|
||||||
for (int i = 0; i < valueLocks.size(); i++) {
|
for (int i = 0; i < valueLocks.size(); i++) {
|
||||||
valueLocks.getAt(i).lock();
|
valueLocks.getAt(i).lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ImmutableList<String> labelValues : keys) {
|
try {
|
||||||
this.values.put(labelValues, 0);
|
for (ImmutableList<String> labelValues : values.asMap().keySet()) {
|
||||||
this.valueStartTimestamps.put(labelValues, startTimestamp);
|
this.values.put(labelValues, 0);
|
||||||
}
|
this.valueStartTimestamps.put(labelValues, startTimestamp);
|
||||||
|
}
|
||||||
for (int i = 0; i < valueLocks.size(); i++) {
|
} finally {
|
||||||
valueLocks.getAt(i).unlock();
|
for (int i = 0; i < valueLocks.size(); i++) {
|
||||||
|
valueLocks.getAt(i).unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue