[concurrency-interest] Concurrent telemetry gathering

Gregg Wonderly gergg at cox.net
Wed Nov 15 21:27:07 EST 2006


Tim Peierls wrote:
> Do you really need avgIntvMinusOne? 

I suppose not, but am trying to minimize CPU as much as possible as this will be 
a very active part of the code.

 > How about making avgIntv volatile,
> get rid of avgInvMinusOne, remove the synchronized keyword from 
> setAverageInterval, and have run() look like this:
> 
> public final void run() {
>     int a = avgIntv;
>     int r = crecv.getAndSet(0);
>     int x = cxmit.getAndSet(0);
>     synchronized (this) {
>         recv = ((recv * (a-1)) + r) / a;
>         xmit = ((xmit * (a-1)) + x) / a;
>     }
> }

I was worried about concurrent access to avgIntv in the setter.   Copying its 
value and using that as an atomically created single value should solve that 
problem!

> Also, make crecv and cxmit final, add @GuardedBy("this") to recv and 
> xmit, and make conn final in addition to transient.

Okay, all good ideas!

> What's the serializiability for? Will deserialization resubmit map 
> entries to the STPE?

It just goes via Jini/RMI to a remote console that uses the computed numbers to 
display some statistics.  It never goes back into an STPE.

Gregg Wonderly



More information about the Concurrency-interest mailing list