Replace map with set. (#9833)
Motivation: Replace Map with Set. `reportedLeaks` has better semantics as a Set, and if it is a Map, it seems that the value of this Map has no meaning to us. Modifications: Use Set. Result: Cleaner code
This commit is contained in:
parent
9ba13f0afc
commit
df121e5e55
@ -168,7 +168,8 @@ public class ResourceLeakDetector<T> {
|
|||||||
Collections.newSetFromMap(new ConcurrentHashMap<DefaultResourceLeak<?>, Boolean>());
|
Collections.newSetFromMap(new ConcurrentHashMap<DefaultResourceLeak<?>, Boolean>());
|
||||||
|
|
||||||
private final ReferenceQueue<Object> refQueue = new ReferenceQueue<Object>();
|
private final ReferenceQueue<Object> refQueue = new ReferenceQueue<Object>();
|
||||||
private final ConcurrentMap<String, Boolean> reportedLeaks = PlatformDependent.newConcurrentHashMap();
|
private final Set<String> reportedLeaks =
|
||||||
|
Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
||||||
|
|
||||||
private final String resourceType;
|
private final String resourceType;
|
||||||
private final int samplingInterval;
|
private final int samplingInterval;
|
||||||
@ -271,7 +272,6 @@ public class ResourceLeakDetector<T> {
|
|||||||
|
|
||||||
private void clearRefQueue() {
|
private void clearRefQueue() {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
DefaultResourceLeak ref = (DefaultResourceLeak) refQueue.poll();
|
DefaultResourceLeak ref = (DefaultResourceLeak) refQueue.poll();
|
||||||
if (ref == null) {
|
if (ref == null) {
|
||||||
break;
|
break;
|
||||||
@ -288,7 +288,6 @@ public class ResourceLeakDetector<T> {
|
|||||||
|
|
||||||
// Detect and report previous leaks.
|
// Detect and report previous leaks.
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
DefaultResourceLeak ref = (DefaultResourceLeak) refQueue.poll();
|
DefaultResourceLeak ref = (DefaultResourceLeak) refQueue.poll();
|
||||||
if (ref == null) {
|
if (ref == null) {
|
||||||
break;
|
break;
|
||||||
@ -299,7 +298,7 @@ public class ResourceLeakDetector<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String records = ref.toString();
|
String records = ref.toString();
|
||||||
if (reportedLeaks.putIfAbsent(records, Boolean.TRUE) == null) {
|
if (reportedLeaks.add(records)) {
|
||||||
if (records.isEmpty()) {
|
if (records.isEmpty()) {
|
||||||
reportUntracedLeak(resourceType);
|
reportUntracedLeak(resourceType);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user