how to get java process virtual memory in windows

181 views Asked by At

I'm trying to get the physical and virtual memeory that my Java process is using in Windows system, like the taskmgr does.

I'm able to get the physical memory of my Java progress, but I cannot get the virtual memory. Now I'm thinking using Windows API to get the process virtual memory, however, I cannot find the function that is working.

Is there another way to get the virtual memory of my java progress?

1

There are 1 answers

0
jelly On

Problem solved!

long size = 0;
        OperatingSystemMXBean osm = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        if (null != osm) {
            size = osm.getCommittedVirtualMemorySize() / 1024L;
        }