On 14.09.2006 14:04 lordy wrote:
> Hi, I want to keep a running 'int' total across threads but without the
> 'synchronized' overhead. (This total will be spinning pretty fast).
>
> I'm guessing Most processors have some kind of atomic (and hopefully) thread safe increment command.
> However a big of Googling suggests this may be possible in Java 1.5 but
> not in Java 1.4.2 ('Twas an IBM article http://www-128.ibm.com/developerwork...ry/j-jtp11234/)
>
> I guess the most performant(?) option is to maintain separate totals and
> combine them at report time?
>
The perfomance "penalty" of a synchronized block is relatively small.
I think there is an article on DeveloperWorks that de-mystifies the
common believe that synchronize will make things slower. If I recall the
article correctly this was true for JDK up to 1.3 but starting with 1.4
(or 1.5 not 100% sure about that) the overhead is so small that it does
not justify the effort to avoid it.
Thomas
--
It's not a RootKit - it's a Sony