• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Get RAM Usage

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am new to Coderanch but glad to be here.

I am pretty noob to Java and Eclipse. Please go easy with me.

I want to get current RAM usage of my computer and display it in Console View of Eclipse? How can I achieve this?

Cheers
 
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,

Welcome to the Ranch.

jconsole is the interactive utility that comes with all Java SDKs. This is used to view current system status for memory. http://docs.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html

MAT is a tool for Eclipse that allows you to analyze your memory use. https://www.eclipse.org/mat/


HTH.
Roger

 
John Brendan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Roger,

Thanks for the link but I just gawk at the page. I am pretty noob to programming. I do not know what to do on that page. Could you write me the code so I can test in Eclipse please?

Cheers
 
Ranch Hand
Posts: 153
Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Brendan wrote:Could you write me the code so I can test in Eclipse please?



There is no code involved. Both of these links are for tools, not code. YOu need to start / install them. And the links should provide you with all the info you need to do that.
 
John Brendan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Hoppmann wrote:

John Brendan wrote:Could you write me the code so I can test in Eclipse please?



There is no code involved. Both of these links are for tools, not code. YOu need to start / install them. And the links should provide you with all the info you need to do that.



Hi Jan,

Thank you very much for reply.

Sorry for confusion. Probably I did not made myself clear. I want to write a Java program and send the computer RAM usage to output, in my case to Eclipse's Console View. Something like:



I added ??? as placeholder for RAM usage because I do not know how to retrieve RAM usage by Java. I hope I could express myself more clearly this time. If not please let me know.

Cheers
 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To do that you could probably use the following implementation:



This code fragment uses the Runtime class to acquire the total amount of memory associated with the invocation of the JVM through calling the static method getRuntime() which returns the the runtime object associated with the current Java application. After you get the runtime object invoke the totalMemory() method on this object to get the total memory, do the same to get the free amount of memory, then subtract to get amount used.
 
John Brendan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rico Felix wrote:To do that you could probably use the following implementation:



This code fragment uses the Runtime class to acquire the total amount of memory associated with the invocation of the JVM through calling the static method getRuntime() which returns the the runtime object associated with the current Java application. After you get the runtime object invoke the totalMemory() method on this object to get the total memory, do the same to get the free amount of memory, then subtract to get amount used.



Hi Rico,

Thank you very much for code listing. It helped a lot.

Cheers
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get total memory from Java Runtime object only Returns the total amount of memory in the Java virtual machine. This is not the same as RAM, or memory available in the OS.
 
Maybe he went home and went to bed. And took this tiny ad with him:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic