File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Retrieve Objects From Heap - Java API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Retrieve Objects From Heap - Java API" Watch "Retrieve Objects From Heap - Java API" New topic
Author

Retrieve Objects From Heap - Java API

Sam Pablo
Greenhorn

Joined: Apr 08, 2010
Posts: 18

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.


Thanks,

Sud.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1944
    
  28
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

Joined: Apr 08, 2010
Posts: 18

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

Joined: Aug 07, 2007
Posts: 1944
    
  28
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

Joined: Mar 17, 2011
Posts: 7063
    
  16

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

Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Sam Pablo
Greenhorn

Joined: Apr 08, 2010
Posts: 18

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

Joined: Apr 08, 2010
Posts: 18

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Retrieve Objects From Heap - Java API
 
Similar Threads
hashing collision
Could any one please explain this program
Objects on Heap
How do Java Heap looks like?
Doubt regarding clone method