Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.palinacquisition!news.posted.palinacquisition.POSTED!not-for-mail NNTP-Posting-Date: Mon, 26 Sep 2011 17:22:04 -0500 Date: Mon, 26 Sep 2011 15:22:03 -0700 From: Peter Duniho User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Blocking IO thread-per-connection model: possible to avoid polling? References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 22 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 50.46.118.188 X-Trace: sv3-fer74lGu73Vitu+48yB6MD0afsiv3dLsKV+UAa0wZK2EXkLa+jUB10VCSVD6Cvfl/COrhAE0GLjr6H3!yPF5uErymQ2QXrAIRWiN9VNGd3i6SbZONOTgMb/vPZMHvkqqPTuc6qN7p0jT8BsXzPUVw1Dc1OSD!6r2lk2YZIg8J31PVqesCGjPQo2aWBs8aobthej03Kts= X-Complaints-To: abuse@iinet.com X-DMCA-Complaints-To: abuse@iinet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2407 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8347 On 9/26/11 3:09 PM, Giovanni Azua wrote: > Hello, > > I'm firstly implementing this "thread-per-connection model" on the Server > component where one thread is responsible for reading the requests and > sending results back to the client, it is not responsible for actually > processing the requests though. I can gracefully (cleanup) stop the thread > by doing socket.getChannel().close() see the snippet below. However, in > order to send data, I also need to interrupt the Thread while it is blocked > waiting for input. Apparently the only way to do this without closing the > channel as side effect is to do polling? Why do you need to interrupt the thread in order to send data? You should be able to just get the output stream from the socket when you create it, and then use that any time you want to send data. The thread that reads from the socket shouldn't need to be responsible for sending at all (except possibly as an optimization in the case where it knows right away it has something to send as a response to something it's just read). Pete