Guest User

Untitled

a guest
Sep 14th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. private long getFreeMemoryComputer() {
  2. try {
  3. OperatingSystemMXBean system = ManagementFactory.getOperatingSystemMXBean();
  4. Method getFreeMemory = system.getClass().getMethod("getFreePhysicalMemorySize");
  5. getFreeMemory.setAccessible(true);
  6. return (long) getFreeMemory.invoke(system);
  7. } catch (Exception e) {
  8. return -1;
  9. }
  10. }
  11.  
  12. private long getTotalMemoryComputer() {
  13. try {
  14. OperatingSystemMXBean system = ManagementFactory.getOperatingSystemMXBean();
  15. Method getTotalMemory = system.getClass().getMethod("getTotalPhysicalMemorySize");
  16. getTotalMemory.setAccessible(true);
  17. return (long) getTotalMemory.invoke(system);
  18. } catch (Exception e) {
  19. return -1;
  20. }
  21. }
Add Comment
Please, Sign In to add comment