Introduce needReport
for ResourceLeakDetector
. (#9910)
Motivation: We can extend `ResourceLeakDetector` through `ResourceLeakDetectorFactory`, and then report the leaked information by covering `reportTracedLeak` and `reportUntracedLeak`. However, the behavior of `reportTracedLeak` and `reportUntracedLeak` is controlled by `logger.isErrorEnabled()`, which is not reasonable. In the case of extending `ResourceLeakDetector`, we sometimes need `needReport` to always return true instead of relying on `logger.isErrorEnabled ()`. Modification: introduce `needReport` method and let it be `protected` Result: We can control the report leak behavior.
This commit is contained in:
parent
76fb4c894a
commit
b82258b72f
@ -274,8 +274,18 @@ public class ResourceLeakDetector<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the return value is {@code true}, {@link #reportTracedLeak} and {@link #reportUntracedLeak}
|
||||||
|
* will be called once a leak is detected, otherwise not.
|
||||||
|
*
|
||||||
|
* @return {@code true} to enable leak reporting.
|
||||||
|
*/
|
||||||
|
protected boolean needReport() {
|
||||||
|
return logger.isErrorEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
private void reportLeak() {
|
private void reportLeak() {
|
||||||
if (!logger.isErrorEnabled()) {
|
if (!needReport()) {
|
||||||
clearRefQueue();
|
clearRefQueue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user