On 28/11/10 20:43, Mike Schilling wrote:
"Steven Simpson" <ss@domain.invalid> wrote in message
news:5kpas7-paa.ln1@news.simpsonst.f2s.com...
Maybe you can get away with a ConcurrentMap<Key, RTSUser>, if you want
to avoid synchronization:
ConcurrentMap is what I'm using. The consensus seems to be that it's
the best choice.
I understand your OP better now. Basically, it seems you already had
the structures we were talking about:
1. Obviously, a member of RTS points to a separate statistics object
which is also pointed to by the weak reference.
Your RTS is the RTSHandle. Your 'separate statistics object' is RTSImpl.
So you need a container of RTSUsers. That was served by the
Map<Reference<RTSHandle>, RTSImpl> in ClassCastException's original
suggestion, and a Collection<RTSUser> will suffice here.
Your weak reference is my RTSUser. You're using a ConcurrentMap (of
<Reference<RTS>, Boolean>, I presume) as a kind of set, which
corresponds to the Collection<RTSUser> above, used to hang on to
references.
Actually, you must have extended WeakReference in order to point it
(strongly) at the separate statistics object...?
Or you're already using a ConcurrentMap<Reference<RTS>,
SeparateStatisticsObject> as CCE
suggested.
(The usage pattern is a bit unusual, since there are effectively no
lookups. There's a put() when the reference is created, and a
remove() when it's pulled out of the reference queue.)
To make it a little less unusual, can you afford to use
Collections.newSetFromMap here, since you're only using normal puts and
removes?