commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Cooper <mfncoo...@gmail.com>
Subject Re: [lang] FastNumberFormat?
Date Thu, 12 Aug 2004 16:33:22 GMT
On Tue, 10 Aug 2004 22:10:22 -0700, Craig McClanahan <craigmcc@gmail.com> wrote:
> On Tue, 10 Aug 2004 20:10:46 -0700, Martin Cooper <mfncooper@gmail.com> wrote:
> > On Tue, 10 Aug 2004 17:27:30 -0400, Gary Gregory
> > <ggregory@seagullsoftware.com> wrote:
> > > Why not give each thread its own DecimalFormat instance in a thread
> > > local variable? Then you do not have to worry about it.
> >
> > That's most likely what I'll end up doing. I was just hoping to get
> > rid of synchronisation altogether, including the lock checks.
> >
> 
> You might want to review how ThreadLocal variables are implemented,
> though ... it's most likely to be some sort of HashMap keyed by
> classloader, and the get/put operations to update your thread's local
> copy are likely to be synchronized internally.

Interesting point. I've looked at the code, and this doesn't appear to
be the case, at least for Sun JDK 1.4.2.

> The best way to avoid synchronization is likely to create one in a
> local variable, then pass it around to whomever needs it.  Ugly, but
> performance hacks are sometimes like that.

I found a better way - not using DecimalFormat at all. ;-) I looked
more closely at the usage that's causing the problem, and it turns out
that we can just write our own vastly simplified version.

--
Martin Cooper


> > --
> > Martin Cooper
> 
> Craig
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

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


Mime
View raw message