Java 查找分配给进程的虚拟内存量

Java 查找分配给进程的虚拟内存量,java,memory,memory-management,sigar,Java,Memory,Memory Management,Sigar,有没有办法找出分配给特定进程的虚拟内存总量?我有一个程序,我也在放一个性能跟踪器,它将监控进程使用了多少内存,还有多少剩余内存可供使用 为此,我需要知道为进程分配了多少内存。有没有一种在Java中实现这一点的方法?我正在Windows 7上运行。 此外,我目前一直在使用Sigar类来监视其他内存统计信息。sigar是否有特定的类/函数可以找到我要查找的内容?您可以使用 在计算所用内存的代码中:- Runtime runtime = Runtime.getRuntime(); // Get the

有没有办法找出分配给特定进程的虚拟内存总量?我有一个程序,我也在放一个性能跟踪器,它将监控进程使用了多少内存,还有多少剩余内存可供使用

为此,我需要知道为进程分配了多少内存。有没有一种在Java中实现这一点的方法?我正在Windows 7上运行。

此外,我目前一直在使用Sigar类来监视其他内存统计信息。sigar是否有特定的类/函数可以找到我要查找的内容?

您可以使用

在计算所用内存的代码中:-

Runtime runtime = Runtime.getRuntime(); // Get the Java runtime
long memory = runtime.totalMemory() - runtime.freeMemory(); // Calculate the used memory

要添加@Mitesh提到的更多内容

        int var=1; // for bytes. you can change here to print in MB or KB as you wish
        log.info("************************* PRINTING MEMORY USAGE - BEGIN **************");

        Runtime runtime = Runtime.getRuntime();

        /* Total number of processors or cores available to the JVM */
        log.info("Available processors (cores): "
                + runtime.availableProcessors());

        /* This will return Long.MAX_VALUE if there is no preset limit */
        long maxMemory = runtime.maxMemory();
        /* Maximum amount of memory the JVM will attempt to use */
        log.info("Maximum memory : "
                + (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory / var));

        /* Total memory currently available to the JVM */
        long totalMemory = runtime.totalMemory() / var;
        log.info("Total memory available to JVM : "
                + totalMemory);

        /* Total amount of free memory available to the JVM */
        long freeMemory = runtime.freeMemory() / var;
        log.info("Free memory : " + freeMemory);

        // Calculate the used memory
        long usedMemory = totalMemory - freeMemory; 
        log.info("Used memory : " + usedMemory);

请参考:哎呀,我删除了评论,我在问‘我们是否在方法执行结束时添加这个’。。tks+1I为Web开发人员提供了EclipseJavaEEIDE,Indigo。我安装了visual VM,但无法按此处所述启动它:。你知道吗?