commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: [LANG] - suggestions for new Identity Hash code classes
Date Tue, 16 Sep 2008 12:56:54 GMT
On 16/09/2008, Simon Kitching <skitching@apache.org> wrote:
> sebb schrieb:
>
> > I think I've found a fix to LANG-459 - which is to borrow some code
> > from Apache Axis.
> >
> > The required code is a single short class - IDKey (e.g.
> >
> http://www.jdocs.com/axis/1.4/org/apache/axis/utils/IDKey.html)
> >
> > It could be added as a private class of HashCodeBuilder, but it has
> > wider use, so should probably be added as a public class.
> >
> >
>  Seems reasonable to me.  It does look like it will solve LANG-459. And as
> you say, this problem may be reasonably common.
>
>  What about making the IDKey class final? One thing that does concern me is
> that HashSet lookup using an Integer object as the key should be pretty
> fast. Using an IDKey object as the key may not perform as well. Making IDKey
> final would at least help. And I cannot see any reason why someone would
> want to subclass IDKey.
>

Good idea. I already made the fields final.

>  One other concern is regarding garbage collection. From a brief look at the
> code, this thread-local registry object contains a set of Integer hashcodes.
> With this change, the set will now contain real hard references to objects,
> preventing them from being garbage-collected while they are in the set. Does
> this matter?

The entries are only retained in the registry during the hashcode
calculation - if any were left behind they could mess up subsequent
calls in the same thread.

As far as I can see, the code always removes any items that are added,
but it would be worth double-checking that.

> > Seems to me it would also be useful to add IdentityHashMap and
> > IdentityHashSet classes as well, given that LANG still targets Java
> > 1.3.
> >
> > WDYT?
> >
> > And do these classes need a new package, or would the top-level package be
> OK?
> >
> >
>
>  No opinion.
>
>  Cheers,
>  Simon
>
>
>
> ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>  For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message