千家信息网

JVM常见问题有哪些

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,这篇文章主要介绍JVM常见问题有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!多个 java 程序设置内存超过系统内存范围会阻止启动吗?即程序在启动时就占满其内存,还是按需
千家信息网最后更新 2026年11月03日JVM常见问题有哪些

这篇文章主要介绍JVM常见问题有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

  1. 多个 java 程序设置内存超过系统内存范围会阻止启动吗?即程序在启动时就占满其内存,还是按需增长? 例如:一台主机,能启动5个默认配置(By default, the JVM will use MaxMemory/4 )的程序吗? 一同事说在一个128G内存的机器上无法启动新的java程序,询问得知此服务器启动过四个java应用,后查看服务器内存占满包括swap。

  2. 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

  1. 如果主机内存资源紧张,会有抑制JVM虚拟机内存增长的机制吗? 线上同一个服务有多个实例,在内存资源紧张的主机上的实例占用的内存要低于其他实例

  1. 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

  1. java 内存与 运行在 Docker 中 Linux 显示进程使用内存,Docker contener 使用内存的关系

  2. java 内存与 运行在 kubernetes 中 Linux 显示进程使用内存,Docker contener 使用内存, POD 使用内存的关系

cat << \EOF > 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

以上是"JVM常见问题有哪些"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

内存 进程 程序 主机 实例 系统 服务 常见 常见问题 问题 操作系统 使用量 内容 多个 时候 服务器 篇文章 资源 增长 运行 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 新华互联网科技 为想互联网科技怎么样 互联网科技工作委员会副主任毛军 科技互联网龙头 金融科技与互联网金融 合肥互联网科技公司 互联网 的科技创新 互联网未来科技 以房互联网科技 奇酷互联网络科技公司 博兴的互联网电子科技公司 恒银科技与互联网金融 常德市电业局互联网科技部 互联网新科技动漫ppt素材 深圳市罗太互联网科技有限公司 互联网科技公司营业执照怎么办理 互联网领先科技宣传片 艺电能源互联网科技有限公司招聘 绵阳真晨互联网科技有限公司 互联网科技对化妆品行业 北京互联网科技有限公司 齐家互联网科技 奇酷互联网科技公司 无线互联网科技 深圳国际航运科技和互联网 互联网科技博主是什么意思 昭通互联网科技选哪家 美国互联网科技实力 北京品多多互联网科技有限公司 如何强化互联网金融科技
0