Link to home
Start Free TrialLog in
Avatar of st5
st5

asked on

instantiated objects of one class

Hello,
At runtime, is there a way to get the references of all objects that are instances of one given class?
Tks
st5
Avatar of Sasha_M
Sasha_M

Well, the Class class doesn't define such a method, so I would think there isn't one. You can have a static Vector for your class and add each instance to it on construction and remove it on destruction (finalize()).
finalize() is not always guaranteed to be called,for threads at least.

Thread t=new Thread();
Thread [] currentThreads= new Thread [t.activeCount()];
t.enumerate(currentThreads);

there maybe a method to do it
A. AFAIK finalize() is guaranteed to be called, just the exact time is not guaranteed to be anything.
B. >> At runtime, is there a way to get the references of all
>> objects that are instances of one given class?
What's up with the thread count? The question was about instances of a class.
ASKER CERTIFIED SOLUTION
Avatar of mbormann
mbormann

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, I see what you mean now :-)
But I think that will only give you the active (running) Threads, not all instances of class Thread.
>>>>>At runtime, is there a way to get the references of all objects that are instances of one given class?

Yes Sasha_M I dont know how to get all other objects ,but I think for all threads at least you can keep track of thru this method.