From ae0939d55f1518b0d7f1cb207c0feb568c0d2d0d Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 7 Jun 2016 09:18:23 -0400 Subject: [PATCH] GH-1824: Comment Out HeapDumper in s-i-test Resolves #1824 --- .../integration/test/util/HeapDumper.java | 136 +++++++++--------- 1 file changed, 64 insertions(+), 72 deletions(-) diff --git a/spring-integration-test/src/main/java/org/springframework/integration/test/util/HeapDumper.java b/spring-integration-test/src/main/java/org/springframework/integration/test/util/HeapDumper.java index 385fcdca6a..27aaabd171 100644 --- a/spring-integration-test/src/main/java/org/springframework/integration/test/util/HeapDumper.java +++ b/spring-integration-test/src/main/java/org/springframework/integration/test/util/HeapDumper.java @@ -16,22 +16,14 @@ package org.springframework.integration.test.util; -import java.io.File; -import java.lang.management.ManagementFactory; - -import javax.management.MBeanServer; - -import com.sun.management.HotSpotDiagnosticMXBean; - /** * Use to take a heap dump programmatically. Useful to examine the heap when debugging * sporadic test failures. - *

- * Usage: {@code HeapDumper.dumpHeap("/tmp/foo.hprof");} - *

- * If the file exists already, it will be replaced. - *

- * Courtesy: + *

Commented out because it uses access-restricted classes and some IDEs won't build + * the project without relaxing the access restriction. + *

Usage: {@code HeapDumper.dumpHeap("/tmp/foo.hprof");} + *

If the file exists already, it will be replaced. + *

Courtesy: * https://blogs.oracle.com/sundararajan/entry/programmatically_dumping_heap_from_java *

  * See https://docs.oracle.com/javase/8/docs/jre/api/management/extension/com/sun/management/HotSpotDiagnosticMXBean.html#dumpHeap-java.lang.String-boolean-
@@ -42,64 +34,64 @@ import com.sun.management.HotSpotDiagnosticMXBean;
  */
 public class HeapDumper {
 
-	// This is the name of the HotSpot Diagnostic MBean
-	private static final String HOTSPOT_BEAN_NAME = "com.sun.management:type=HotSpotDiagnostic";
-
-	// field to store the hotspot diagnostic MBean
-	private static volatile HotSpotDiagnosticMXBean hotspotMBean;
-
-	private HeapDumper() {
-		super();
-	}
-
-	public static void dumpHeap(String fileName) {
-		dumpHeap(fileName, true);
-	}
-
-	public static void dumpHeap(String fileName, boolean live) {
-		File file = new File(fileName);
-		if (file.exists()) {
-			file.delete();
-		}
-		// initialize hotspot diagnostic MBean
-		initHotspotMBean();
-		try {
-			hotspotMBean.dumpHeap(fileName, live);
-		}
-		catch (RuntimeException re) {
-			throw re;
-		}
-		catch (Exception exp) {
-			throw new RuntimeException(exp);
-		}
-	}
-
-	// initialize the hotspot diagnostic MBean field
-	private static void initHotspotMBean() {
-		if (hotspotMBean == null) {
-			synchronized (Object.class) {
-				if (hotspotMBean == null) {
-					hotspotMBean = getHotspotMBean();
-				}
-			}
-		}
-	}
-
-	// get the hotspot diagnostic MBean from the
-	// platform MBean server
-	private static HotSpotDiagnosticMXBean getHotspotMBean() {
-		try {
-			MBeanServer server = ManagementFactory.getPlatformMBeanServer();
-			HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server, HOTSPOT_BEAN_NAME,
-					HotSpotDiagnosticMXBean.class);
-			return bean;
-		}
-		catch (RuntimeException re) {
-			throw re;
-		}
-		catch (Exception exp) {
-			throw new RuntimeException(exp);
-		}
-	}
+//	// This is the name of the HotSpot Diagnostic MBean
+//	private static final String HOTSPOT_BEAN_NAME = "com.sun.management:type=HotSpotDiagnostic";
+//
+//	// field to store the hotspot diagnostic MBean
+//	private static volatile HotSpotDiagnosticMXBean hotspotMBean;
+//
+//	private HeapDumper() {
+//		super();
+//	}
+//
+//	public static void dumpHeap(String fileName) {
+//		dumpHeap(fileName, true);
+//	}
+//
+//	public static void dumpHeap(String fileName, boolean live) {
+//		File file = new File(fileName);
+//		if (file.exists()) {
+//			file.delete();
+//		}
+//		// initialize hotspot diagnostic MBean
+//		initHotspotMBean();
+//		try {
+//			hotspotMBean.dumpHeap(fileName, live);
+//		}
+//		catch (RuntimeException re) {
+//			throw re;
+//		}
+//		catch (Exception exp) {
+//			throw new RuntimeException(exp);
+//		}
+//	}
+//
+//	// initialize the hotspot diagnostic MBean field
+//	private static void initHotspotMBean() {
+//		if (hotspotMBean == null) {
+//			synchronized (Object.class) {
+//				if (hotspotMBean == null) {
+//					hotspotMBean = getHotspotMBean();
+//				}
+//			}
+//		}
+//	}
+//
+//	// get the hotspot diagnostic MBean from the
+//	// platform MBean server
+//	private static HotSpotDiagnosticMXBean getHotspotMBean() {
+//		try {
+//			MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+//			HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server, HOTSPOT_BEAN_NAME,
+//					HotSpotDiagnosticMXBean.class);
+//			return bean;
+//		}
+//		catch (RuntimeException re) {
+//			throw re;
+//		}
+//		catch (Exception exp) {
+//			throw new RuntimeException(exp);
+//		}
+//	}
 
 }