Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the frequently asked questions about JVM

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces what are the common problems of JVM. It is very detailed and has a certain reference value. Friends who are interested must finish reading it.

Does multiple java programs set memory beyond the system memory range to prevent startup? That is, does the program fill up its memory when it starts, or does it grow on demand? For example, can a host start programs with 5 default configurations (By default, the JVM will use MaxMemory/4)? A colleague said that a new java program could not be started on a machine with 128 gigabytes of memory, asked to learn that the server had started four java applications, and then checked that the server was full of memory, including swap.

When will JVM release memory to the operating system? Or when JVM process memory usage will be reduced, in theory, JVM "will not (or is extremely harsh)" to release unused memory to the operating system, monitoring found that JVM process memory usage will be reduced, which memory https://www.geekyhacker.com/2019/01/04/jvm-does-not-release-memory/ https://stackoverflow.com/questions/6785754/jvm-process-vs-jvm-heap-memory-usage is released

If the host memory resources are tight, is there a mechanism to restrain the memory growth of JVM virtual machines? There are multiple instances of the same service online, and instances on hosts with tight memory resources consume less memory than other instances.

The relationship between java memory and memory used by Linux display process

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

The relationship between java memory and the memory used by Linux display process and Docker contener running in Docker

The relationship between java memory and the memory used by Linux display process, Docker contener and POD running in kubernetes

Cat JmxTest.javaimport 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 specificimport com.sun.tools.attach.VirtualMachine;// Sun implementation specificimport 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 () }} EOFjavac-Djava.ext.dirs=/usr/java/jdk1.8.0_121/lib JmxTest.javajava-Djava.ext.dirs=/usr/java/jdk1.8.0_121/lib JmxTest above is all the content of the article "what are JVM FAQs?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report