Howto keep track of GC, without letting the monitored object die?

Tony Printezis Antonios.Printezis at sun.com
Wed Mar 25 09:00:39 PDT 2009


(resending with the correct CC)

Tony Printezis wrote:
> Clemens,
>
> You can use WeakReferences. Have a look at this article:
>
> http://java.sun.com/developer/technicalArticles/javase/finalization/
>
> In particular, the An Alternative To Finalization section.
>
> Tony
>
> Clemens Eisserer wrote:
>> Hello,
>>
>> First of all sorry for beeing off-topic.
>> I am developing a distributed object system, where I need to keep
>> track wether an Object is still referenced, without actually let it
>> die.
>> Only if server- and client-side object are no longer referenced, they
>> both may be freed by the GC.
>>
>> With finalizers I would be able to do something like this:
>>
>> class SharedObject {
>>     private Object gcMonitor = new Object() {
>>          protected void finalize() {
>>             RefernceManager.addStrongReference(SharedObject.this);
>>             Server.objectUnreferenced(SharedObject.this);
>>         }
>>     }
>> }
>>
>> Once the server knows both parts are unreferenced, it can release all
>> strong references and the object can be reclaimed by the GC.
>>
>> However I fear that this would really stress the jvm. Is it possible
>> to archive the same using References and ReferenceQueues?
>> Are there patterns which make the knowledge about the object obsolete?
>>
>> Thanks, Clemens
>>   
>

-- 
---------------------------------------------------------------------
| Tony Printezis, Staff Engineer   | Sun Microsystems Inc.          |
|                                  | MS UBUR02-311                  |
| e-mail: tony.printezis at sun.com   | 35 Network Drive               |
| office: +1 781 442 0998 (x20998) | Burlington, MA 01803-2756, USA |
---------------------------------------------------------------------
e-mail client: Thunderbird (Linux)





More information about the hotspot-gc-dev mailing list