commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory" <>
Subject RE: [lang] org.apache.commons.lang.Entities
Date Wed, 26 Apr 2006 15:32:11 GMT

To top it all off the behavior is probably different b/w Java 1.4 and

We could:

- Let users call StringEscapeUtils once to init the data like David
- Change the init in Entities to lazy-init methods (which must be
- Change the init in Entities to use an on-demand holder class 

See "Effective Java" by J. Bloch, Item 48, for multi-threaded init


> -----Original Message-----
> From: Gaulin, David: #CIPO - OPIC []
> Sent: Wednesday, April 26, 2006 5:09 AM
> To:
> Subject: [lang] org.apache.commons.lang.Entities
> Hello,
> Not sure if it is the right mailling list but here we go anyway.
> I am currently using the class (well I am using the
> which uses that class).  Works really good,
saved me a lot
> of time.  My thanks to the people who wrote it.
> I have encountered a little problems with it taught.  Nothing major
but I just
> taugth I would share since it migth be of interest to you.
> I have an heavily multithreaded process that runs on a really under
> server.  All those threads access the StringEscapeUtils.escapeXml()
> pretty much at the same time.  What happens is that by the time the
Second or
> Third Thread calls the StringEscapeUtils.escapeXml() the static
initialization in
> the class has not completed yet.  That block in
>     static {
>         XML = new Entities();
>         XML.addEntities(BASIC_ARRAY);
>         XML.addEntities(APOS_ARRAY);
>     }
> I don't get a NullPointer so it seems that XML = new Entities() is
actually being
> executed before the other Thread starts but the
> on the other hand is not executed before the other thread starts.  So
when the
> second or third thread calls the StringEscapeUtils.escapeXml() it
doesn't escape
> the BASIC_ARRAY or APOS_ARRAY entities.  To fix it, in my code, I just
make sure
> to call StringEscapeUtils.escapeXml() before I start any threads and
it solve the
> problems but if anyone is ever to re-work the class this might be
something to
> look at.
> Just to share.
> Thank
> David

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message