> From: Yilong Li [mailto:yilong...@runtimeverification.com] 
> Subject: Re: svn commit: r1703194 - 
> /tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java

> I am not sure declaring this field as volatile is the right way to fix it
> because the increment is still not atomic. If this counter doesn't have to
> be precise, I think it's OK to allow data races on this field. Otherwise,
> it should be declared as atomic.

Correct; marking the field as volatile serves no purpose here, since the value 
does not need to be precise.  Even making it atomic would not prevent multiple 
threads from iterating over the map concurrently in the backgroundProess() 
method; the only ways to prevent that are having the same lock held on the 
counter and the iteration loop, or the same lock on the counter and a busy flag.

I am concerned that the iterator in the for loop of backgroundProcess() may 
lose its validity if another thread updates the map, but I'll need to study the 
documentation and implementation to see if that's a real concern.  Regardless, 
using one of the forEach*() methods of ConcurrentHashMap would probably be more 
efficient.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to