File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Finding out # of instantiations of a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Finding out # of instantiations of a class" Watch "Finding out # of instantiations of a class" New topic
Author

Finding out # of instantiations of a class

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

I want to write a program that will let me know
all the currently loaded classes in the current
JVM and the number of instantiations for each
loaded class. Reflection allows me to inspect
a class. Is there anything in Java to allow me
to inspect the JVM itself ?
Thanks
Pho


Regards,

Pho
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
First you write a JVM . . . . .
No - seriously - each JVM is slightly different depending on who wrote it. If you write your OWN JVM you can keep track of such things (which is how tools like IDEs do it), but I don't know of any such thing that is required in the Specification for JVMs.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

Cindy,
I was actually asked this in an interview!
I'm sure it couldn't be that hard considering
that there are profiler tools that can do this
by attaching itself to a running JVM.
See http://www.vmgear.com/Pallocationview.html
I'm asking this question because I'm doing an audit
of my interview "performance" as there were a couple
of questions which I fumbled.
Thanks
Pho
[This message has been edited by Pho Tek (edited November 07, 2001).]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Well, then they have figured out something that I haven't (not too surprising actually ).
When you figure it out, can you come back and fill us in?

[This message has been edited by Cindy Glass (edited November 08, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding out # of instantiations of a class
 
Similar Threads
refactoring vs. performance reference
Initialization blocks...
Class loading
another K&B mock question
static blocks