Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieve Objects From Heap - Java API

 
Greenhorn
Posts: 18
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gurus,

I want to retrieve objects from Java Heap, and want to write a code for the same.

Can someone tell me which API should I use to do the same?

Any pointers would be helpful.

Regards,

Sam.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want to retrieve objects from Java Heap, and want to write a code for the same.


Can you explain what you mean by this and also explain what you are trying to achieve.
 
Sam Pablo
Greenhorn
Posts: 18
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony Docherty wrote:

I want to retrieve objects from Java Heap, and want to write a code for the same.


Can you explain what you mean by this and also explain what you are trying to achieve.



Thanks for your interest Tony...

To simplify what I have written, as quoted above, I hope you know tools like JMap, JConsole, JStack, etc, which takes heap dumps.
As far as I can understand, they collect the number of heap objects (which are being referenced or ready for garbage collection). I too want to do the same, say for example, count the total number of objects in the heap, through a Java Code (I do not know how JMap or JConsole does it, maybe by native calls or through Java API).

 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The simple answer is I don't know for sure. I know there is an instrumentation api and I believe these products use that.
A quick google found this site http://www.javamex.com/tutorials/memory/instrumentation.shtml which may be useful to you.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Pablo wrote:To simplify what I have written, as quoted above, I hope you know tools like JMap, JConsole, JStack, etc, which takes heap dumps.
As far as I can understand, they collect the number of heap objects (which are being referenced or ready for garbage collection). I too want to do the same, say for example, count the total number of objects in the heap, through a Java Code (I do not know how JMap or JConsole does it, maybe by native calls or through Java API).


And in addition to Tony's link, you might also want to look at the java.lang.management package that was introduced in 1.6.

However, before you go too far down this road, you'd better be able to justify your decision; because it sounds to me an awful lot like re-inventing the wheel.
I suspect you'll also find you're in a 'bleeding-edge' area where you can't rely on a lot of help, and will probably have to learn a lot of stuff by trial and error.

If someone asked me to do this, my first question to them would be: Why?
And if that didn't stop them, I'd come up with suitably padded estimates of how long it will take, and how much it'll cost (usually the nail in the coffin of any speculative project). And if that didn't stop them, then I'd accept defeat and settle in for a nice 3 month R&D exercise.

One question for you though: Do you really think you need to retrieve objects in order to get a count of them?

Winston
 
Sam Pablo
Greenhorn
Posts: 18
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony Docherty wrote:The simple answer is I don't know for sure. I know there is an instrumentation api and I believe these products use that.
A quick google found this site http://www.javamex.com/tutorials/memory/instrumentation.shtml which may be useful to you.



Thanks Tony..
Thanks for your time..
 
Sam Pablo
Greenhorn
Posts: 18
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Sam Pablo wrote:To simplify what I have written, as quoted above, I hope you know tools like JMap, JConsole, JStack, etc, which takes heap dumps.
As far as I can understand, they collect the number of heap objects (which are being referenced or ready for garbage collection). I too want to do the same, say for example, count the total number of objects in the heap, through a Java Code (I do not know how JMap or JConsole does it, maybe by native calls or through Java API).


And in addition to Tony's link, you might also want to look at the java.lang.management package that was introduced in 1.6.

However, before you go too far down this road, you'd better be able to justify your decision; because it sounds to me an awful lot like re-inventing the wheel.
I suspect you'll also find you're in a 'bleeding-edge' area where you can't rely on a lot of help, and will probably have to learn a lot of stuff by trial and error.

If someone asked me to do this, my first question to them would be: Why?
And if that didn't stop them, I'd come up with suitably padded estimates of how long it will take, and how much it'll cost (usually the nail in the coffin of any speculative project). And if that didn't stop them, then I'd accept defeat and settle in for a nice 3 month R&D exercise.

One question for you though: Do you really think you need to retrieve objects in order to get a count of them?

Winston



Winston, yes, i agree to what you said. It is just that this question was asked to me in one of the interviews, so thought of trying it out. Anyways, thank you for your time
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic