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
At runtime, is there a way to get the references of all objects that are instances of one given class?
Tks
st5
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
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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.