|
@@ -33,28 +33,28 @@ public class DirectMemoryReporterImpl {
|
|
|
public void init() {
|
|
|
// TODO ( 设置netty 参数 复现 OutOfDirectMemoryError 异常 -Dio.netty.maxDirectMemory = 1938)
|
|
|
|
|
|
-// try {
|
|
|
-// Field field = ReflectionUtils.findField(PlatformDependent.class, "DIRECT_MEMORY_COUNTER");
|
|
|
-// field.setAccessible(true);
|
|
|
-// directMemory = (AtomicLong) field.get(PlatformDependent.class);
|
|
|
-// Field field1 = ReflectionUtils.findField(PlatformDependent.class, "DIRECT_MEMORY_LIMIT");
|
|
|
-// field1.setAccessible(true);
|
|
|
-// maxDirectMemory = (Long) field1.get(PlatformDependent.class);
|
|
|
-// } catch (Exception e) {
|
|
|
-// logger.error(e.getMessage());
|
|
|
-// }
|
|
|
-//
|
|
|
-// TimerTask timerTask = new TimerTask() {
|
|
|
-// @Override
|
|
|
-// public void run() {
|
|
|
-// System.out.println("task run:" + new Date());
|
|
|
-// long m = directMemory.get() ;
|
|
|
-// logger.error(BUSINESS_KEY + "maxDirectMemory==={}:{}K", maxDirectMemory , m);
|
|
|
-// }
|
|
|
-// };
|
|
|
-// Timer timer = new Timer();
|
|
|
-// //安排指定的任务在指定的时间开始进行重复的固定延迟执行。这里是每3秒执行一次
|
|
|
-// timer.schedule(timerTask, 10, 2000);
|
|
|
+ try {
|
|
|
+ Field field = ReflectionUtils.findField(PlatformDependent.class, "DIRECT_MEMORY_COUNTER");
|
|
|
+ field.setAccessible(true);
|
|
|
+ directMemory = (AtomicLong) field.get(PlatformDependent.class);
|
|
|
+ Field field1 = ReflectionUtils.findField(PlatformDependent.class, "DIRECT_MEMORY_LIMIT");
|
|
|
+ field1.setAccessible(true);
|
|
|
+ maxDirectMemory = (Long) field1.get(PlatformDependent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ TimerTask timerTask = new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ System.out.println("task run:" + new Date());
|
|
|
+ long m = directMemory.get();
|
|
|
+ logger.error(BUSINESS_KEY + "maxDirectMemory==={}:{}K", maxDirectMemory, m);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Timer timer = new Timer();
|
|
|
+ //安排指定的任务在指定的时间开始进行重复的固定延迟执行。这里是每3秒执行一次
|
|
|
+ timer.schedule(timerTask, 10, 2000);
|
|
|
}
|
|
|
|
|
|
}
|