public static int getTotalPhysicalMemorySizeInMB ( ) { int memorySizeInMB ; try { long memorySizeInBytes = ( ( com . sun . management . OperatingSystemMXBean ) ManagementFactory . getOperatingSystemMXBean ( ) ) . getTotalPhysicalMemorySize ( ) ; memorySizeInMB = ( int ) ( memorySizeInBytes / BYTES_IN_MEGABYTE ) ; } catch ( Exception e ) { memorySizeInMB = - 1 ; } return memorySizeInMB ; }
Returns the total amount of physical memory on the current machine in megabytes .