您好,登錄后才能下訂單哦!
這篇文章主要介紹JVM常見問題有哪些,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
多個 java 程序設置內存超過系統內存范圍會阻止啟動嗎?即程序在啟動時就占滿其內存,還是按需增長? 例如:一臺主機,能啟動5個默認配置(By default, the JVM will use MaxMemory/4 )的程序嗎? 一同事說在一個128G內存的機器上無法啟動新的java程序,詢問得知此服務器啟動過四個java應用,后查看服務器內存占滿包括swap。
JVM 在什么時候會釋放內存給操作系統?或者什么時候 JVM 進程內存使用量會降低 理論上 JVM “不會(或者說極為嚴苛)” 釋放不使用的內存給 操作系統, 監控發現 JVM 進程內存使用量會降低,釋放的是哪塊內存 https://www.geekyhacker.com/2019/01/04/jvm-does-not-release-memory/ https://stackoverflow.com/questions/6785754/jvm-process-vs-jvm-heap-memory-usage
如果主機內存資源緊張,會有抑制JVM虛擬機內存增長的機制嗎? 線上同一個服務有多個實例,在內存資源緊張的主機上的實例占用的內存要低于其他實例
java 內存與 Linux 顯示進程使用內存的關系
jstat https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html Native Memory Tracking https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr007.html jmx command tool emjmxcli
java 內存與 運行在 Docker 中 Linux 顯示進程使用內存,Docker contener 使用內存的關系
java 內存與 運行在 kubernetes 中 Linux 顯示進程使用內存,Docker contener 使用內存, POD 使用內存的關系
cat << \EOF > JmxTest.java import javax.management.*; import javax.management.remote.JMXServiceURL; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXConnector; import java.lang.management.RuntimeMXBean; import static java.lang.management.ManagementFactory.*; import java.net.Socket; import java.net.InetSocketAddress; import java.io.File; import java.io.IOException; import java.util.Properties; // Sun specific import com.sun.tools.attach.VirtualMachine; // Sun implementation specific import sun.management.ConnectorAddressLink; public class JmxTest { /* * Starts the management agent in the target VM */ private static void startManagementAgent(String pid) throws IOException { /* * JAR file normally in ${java.home}/jre/lib but may be in ${java.home}/lib * with development/non-images builds */ String home = System.getProperty("java.home"); String agent = home + File.separator + "jre" + File.separator + "lib" + File.separator + "management-agent.jar"; File f = new File(agent); if (!f.exists()) { agent = home + File.separator + "lib" + File.separator + "management-agent.jar"; f = new File(agent); if (!f.exists()) { throw new RuntimeException("management-agent.jar missing"); } } agent = f.getCanonicalPath(); System.out.println("Loading " + agent + " into target VM ..."); try { VirtualMachine.attach(pid).loadAgent(agent); } catch (Exception x) { throw new IOException(x.getMessage()); } } private static void connect(String pid, String address) throws Exception { if (address == null) { throw new RuntimeException("Local connector address for " + pid + " is null"); } System.out.println("Connect to process " + pid + " via: " + address); JMXServiceURL url = new JMXServiceURL(address); JMXConnector c = JMXConnectorFactory.connect(url); MBeanServerConnection server = c.getMBeanServerConnection(); System.out.println("Connected."); ObjectName directName = ObjectName.getInstance("java.nio:type=BufferPool,name=direct"); MBeanInfo mbInfo = server.getMBeanInfo(directName) ; for(MBeanAttributeInfo i : mbInfo.getAttributes()) { System.out .println(i.getName() + ":" + server.getAttribute(directName , i.getName())); } // RuntimeMXBean rt = newPlatformMXBeanProxy(server, // RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); // System.out.println(rt.getName()); // close the connection c.close(); } private final static String LOCAL_CONNECTOR_ADDRESS_PROP = "com.sun.management.jmxremote.localConnectorAddress"; public static void main(String[] args) throws Exception { String pid = "1"; VirtualMachine vm = VirtualMachine.attach(pid); String agentPropLocalConnectorAddress = (String) vm.getAgentProperties().get(LOCAL_CONNECTOR_ADDRESS_PROP); int vmid = Integer.parseInt(pid); String jvmstatLocalConnectorAddress = ConnectorAddressLink.importFrom(vmid); if (agentPropLocalConnectorAddress == null && jvmstatLocalConnectorAddress == null) { // No JMX Connector address so attach to VM, and load // management-agent.jar startManagementAgent(pid); agentPropLocalConnectorAddress = (String) vm.getAgentProperties().get(LOCAL_CONNECTOR_ADDRESS_PROP); jvmstatLocalConnectorAddress = ConnectorAddressLink.importFrom(vmid); } // Test address obtained from agent properties System.out.println("Testing the connector address from agent properties"); connect(pid, agentPropLocalConnectorAddress); // Test address obtained from jvmstat buffer // System.out.println("Testing the connector address from jvmstat buffer"); // connect(pid, jvmstatLocalConnectorAddress); // // Shutdown application // int port = Integer.parseInt(args[1]); // System.out.println("Shutdown process via TCP port: " + port); // Socket s = new Socket(); // s.connect(new InetSocketAddress(port)); // s.close(); } } EOF javac -Djava.ext.dirs=/usr/java/jdk1.8.0_121/lib JmxTest.java java -Djava.ext.dirs=/usr/java/jdk1.8.0_121/lib JmxTest
以上是“JVM常見問題有哪些”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。