You need remove key from selector collection, add itr.remove() after key = (SelectionKey)itr.next();
On 5/5/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Send jdev mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.jabber.org/mailman/listinfo/jdev > or, via email, send a message with subject or body 'help' to > [EMAIL PROTECTED] > > You can reach the person managing the list at > [EMAIL PROTECTED] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of jdev digest..." > > > Today's Topics: > > 1. Regarding-JSO-Multithreading-Java (Merwin Pinto) > > > > ---------- Forwarded message ---------- > From: "Merwin Pinto" <[EMAIL PROTECTED]> > To: [email protected] > Date: 5 May 2005 13:25:49 -0000 > Subject: [jdev] Regarding-JSO-Multithreading-Java > > > Hi All, > I had downloaded the JSO some time back. I was trying to run the code ..... > now with respect to the example given in ... example/EchoServer.java. > i was connecting to the server , Using the client programme which is also > gien in > examples . Now the server works fine for > most part ...except that some times it goes into a infinite loop....at the > point where the code tries to remove the session ....for some reason it is > not able to remove the session and goes into the infinite loop... > This happens more often when server is running on Linux .... > Can someone help me with this ...why could this be happening ? .... is the KEY > not being cancelled ....??? I am not sure > PLEASE HELP ME ..... Solve This Problem > a part of the code is below... > Thanks a lotregards, Merwin > ------------------------------------------------------- > ------------------------------------------------------- > conn = JSOImplementation.getInstance().createStream("jabber:client"); > src = ChannelStreamSource.createSocket(host, port); > > conn.connect(src); > conn.open(); > src.register(selector, SelectionKey.OP_READ, conn); > > Then ...... > Selector.select() to retrieve the available selection keys, > and process the attached Streams: > > while (selector.select() > 0) { > Iterator itr = selector.selectedKeys().iterator(); > SelectionKey key; > Stream conn; > > while (itr.hasNext()) { > key = (SelectionKey)itr.next(); > conn = (Stream)key.attachment(); > > conn.process(); > if (!conn.getCurrentStatus().isConnected()) > key.cancel(); //Stream disconnected; remove from selector > } > } > > > _______________________________________________ > jdev mailing list > [email protected] > http://mail.jabber.org/mailman/listinfo/jdev > > > _______________________________________________ jdev mailing list [email protected] http://mail.jabber.org/mailman/listinfo/jdev
