You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Leon Rosenberg <ro...@googlemail.com> on 2006/05/28 01:10:05 UTC
[OT] Performance of AtomicLong
Hi,
have someone made some actual measures on performance of atomiclong
compared to old-style synchronization?
Sun stats (http://java.sun.com/developer/technicalArticles/J2SE/concurrency/)
that Atomics are faster than the synchronized() block, but from the
implementation of some methods I would actually see some data:
/**
* Atomically increment by one the current value.
* @return the updated value
*/
public final long incrementAndGet() {
for (;;) {
long current = get();
long next = current + 1;
if (compareAndSet(current, next))
return next;
}
}
as far as I understand calling this function from 3 threads
simulatenously would end in running through this block 6 times. 10
Threads - 55 times. And so on. And this is still performant?
regards
Leon
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: [OT] Performance of AtomicLong
Posted by Leon Rosenberg <ro...@googlemail.com>.
Hi FIlip,
I actually made a test last night:
http://moskito.anotheria.net/AtomicVsSynchronized.html
On suns jdk it seems to be faster, but not on jrockit. And
synchronized on jrockit seems to be faster than atomic on sun on 1
processor machines.
regards
leon
On 5/28/06, Filip Hanik - Dev Lists <de...@hanik.com> wrote:
> yes, compared to using synchronized, this is a huge improvement
>
> Leon Rosenberg wrote:
> > Hi,
> >
> > have someone made some actual measures on performance of atomiclong
> > compared to old-style synchronization?
> > Sun stats
> > (http://java.sun.com/developer/technicalArticles/J2SE/concurrency/)
> > that Atomics are faster than the synchronized() block, but from the
> > implementation of some methods I would actually see some data:
> >
> > /**
> > * Atomically increment by one the current value.
> > * @return the updated value
> > */
> > public final long incrementAndGet() {
> > for (;;) {
> > long current = get();
> > long next = current + 1;
> > if (compareAndSet(current, next))
> > return next;
> > }
> > }
> >
> > as far as I understand calling this function from 3 threads
> > simulatenously would end in running through this block 6 times. 10
> > Threads - 55 times. And so on. And this is still performant?
> >
> > regards
> > Leon
> >
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
> >
>
>
> --
>
>
> Filip Hanik
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: [OT] Performance of AtomicLong
Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
yes, compared to using synchronized, this is a huge improvement
Leon Rosenberg wrote:
> Hi,
>
> have someone made some actual measures on performance of atomiclong
> compared to old-style synchronization?
> Sun stats
> (http://java.sun.com/developer/technicalArticles/J2SE/concurrency/)
> that Atomics are faster than the synchronized() block, but from the
> implementation of some methods I would actually see some data:
>
> /**
> * Atomically increment by one the current value.
> * @return the updated value
> */
> public final long incrementAndGet() {
> for (;;) {
> long current = get();
> long next = current + 1;
> if (compareAndSet(current, next))
> return next;
> }
> }
>
> as far as I understand calling this function from 3 threads
> simulatenously would end in running through this block 6 times. 10
> Threads - 55 times. And so on. And this is still performant?
>
> regards
> Leon
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
--
Filip Hanik
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org