Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 35F8DC49F for ; Mon, 3 Jun 2013 11:04:43 +0000 (UTC) Received: (qmail 27017 invoked by uid 500); 3 Jun 2013 11:04:39 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 26817 invoked by uid 500); 3 Jun 2013 11:04:39 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 26795 invoked by uid 99); 3 Jun 2013 11:04:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jun 2013 11:04:37 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of mgainty@hotmail.com designates 65.55.111.112 as permitted sender) Received: from [65.55.111.112] (HELO blu0-omc2-s37.blu0.hotmail.com) (65.55.111.112) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jun 2013 11:04:30 +0000 Received: from BLU172-W44 ([65.55.111.72]) by blu0-omc2-s37.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 3 Jun 2013 04:04:10 -0700 X-TMN: [IbRjOsmM0wDYDYlB5RZ537zMgS5cp3LS] X-Originating-Email: [mgainty@hotmail.com] Message-ID: Content-Type: multipart/alternative; boundary="_5d6e5e69-3e94-432a-aaf2-4122c280b317_" From: Martin Gainty To: Tomcat Users List Subject: RE: WebSockets Thread Safety question Date: Mon, 3 Jun 2013 07:04:09 -0400 Importance: Normal In-Reply-To: References: , MIME-Version: 1.0 X-OriginalArrivalTime: 03 Jun 2013 11:04:10.0767 (UTC) FILETIME=[134839F0:01CE604A] X-Virus-Checked: Checked by ClamAV on apache.org --_5d6e5e69-3e94-432a-aaf2-4122c280b317_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable /java/util>javap Collections | grep synchronized public static java.util.Collection synchronizedCollection(java.util.Col= lecti on)=3B static java.util.Collection synchronizedCollection(java.util.Collection= =2C jav a.lang.Object)=3B public static java.util.Set synchronizedSet(java.util.Set)=3B static java.util.Set synchronizedSet(java.util.Set=2C java.lang.Object)= =3B public static java.util.SortedSet synchronizedSortedSet(java.util.Sorte= dSet) =3B public static java.util.List synchronizedList(java.util.List)=3B static java.util.List synchronizedList(java.util.List=2C java.lang.Obje= ct)=3B public static java.util.Map synchronizedMap(java.util.Map)=3B public static java.util.SortedMap synchronizedSortedMap(java.util.Sorte= dMap) =3B use java.util.Collections.synchronizedList=20 Martin=20 ______________________________________________=20 Verzicht und Vertraulichkeitanmerkung/Note de d=E9ni et de confidentialit= =E9 Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaeng= er sein=2C so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiter= leitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient l= ediglich dem Austausch von Informationen und entfaltet keine rechtliche Bin= dungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen w= ir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut =EAtre privil=E9gi=E9. Si vous n'=EAtes= pas le destinataire pr=E9vu=2C nous te demandons avec bont=E9 que pour sat= isfaire informez l'exp=E9diteur. N'importe quelle diffusion non autoris=E9e= ou la copie de ceci est interdite. Ce message sert =E0 l'information seule= ment et n'aura pas n'importe quel effet l=E9galement obligatoire. =C9tant d= onn=E9 que les email peuvent facilement =EAtre sujets =E0 la manipulation= =2C nous ne pouvons accepter aucune responsabilit=E9 pour le contenu fourni= . > From: chris@derham.me.uk > Date: Mon=2C 3 Jun 2013 07:42:01 -0300 > Subject: Re: WebSockets Thread Safety question > To: users@tomcat.apache.org >=20 > > When I use the syntax from the samples in the onTextMessage() method=2C= 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 =3D CharBuffer.wrap(cb)=3B > > mmib.myoutbound.writeTextMessage(buffer)=3B > > mmib.myoutbound.flush()=3B > > } > > > > > > Changing it to the following works fine: > > > > for(int i =3D 0=3B i < mmib.size()=3B i++) { > > MyMessageInbound mmib =3D mmiList.get(i)=3B > > CharBuffer buffer =3D CharBuffer.wrap(cb)=3B > > mmib.myoutbound.writeTextMessage(buffer)=3B > > mmib.myoutbound.flush()=3B > > } > > > > However=2C this approach is not as efficient as to use an Iterator=2C u= nless I > > clone the mmiList Collection to iterate over it... >=20 > Can you explain where is the in-efficiency? >=20 > Thanks >=20 > Chris >=20 > --------------------------------------------------------------------- > To unsubscribe=2C e-mail: users-unsubscribe@tomcat.apache.org > For additional commands=2C e-mail: users-help@tomcat.apache.org >=20 = --_5d6e5e69-3e94-432a-aaf2-4122c280b317_--