tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chris derham <ch...@derham.me.uk>
Subject Re: WebSockets Thread Safety question
Date Mon, 03 Jun 2013 10:42:01 GMT
> When I use the syntax from the samples in the onTextMessage() method, I get
> ConcurrentModificationException if I have more than one client sending data
> to the server at the same time:
>
>             for(MyMessageInbound mmib: mmiList){
>                 CharBuffer buffer = CharBuffer.wrap(cb);
>                 mmib.myoutbound.writeTextMessage(buffer);
>                 mmib.myoutbound.flush();
>             }
>
>
> Changing it to the following works fine:
>
>             for(int i = 0; i < mmib.size(); i++) {
>                 MyMessageInbound mmib = mmiList.get(i);
>                 CharBuffer buffer = CharBuffer.wrap(cb);
>                 mmib.myoutbound.writeTextMessage(buffer);
>                 mmib.myoutbound.flush();
>             }
>
> However, this approach is not as efficient as to use an Iterator, unless I
> clone the mmiList Collection to iterate over it...

Can you explain where is the in-efficiency?

Thanks

Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message