• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve Objects From Heap - Java API

 
Sam Pablo
Greenhorn
Posts: 18
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
Tony Docherty
Bartender
Posts: 2939
59
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2939
59
  • Mark post as helpful
  • send pies
  • 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.
 
Winston Gutkowski
Bartender
Pie
Posts: 10091
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic