I have recently had problems with a simple WebSocket sample I'm developing.
Tomcat Version is 7.0.39.
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...
About the mmiList object, why isn't it a Threadsafe Collection?
What's the recommended approach for this?
Regards