[concurrency-interest] Need to kill a single working thread, rather than killing the application
dcholmes at optusnet.com.au
Tue Dec 19 08:31:39 EST 2006
Closing the socket/stream is the preferred method for unblocking a thread
that is stuck on the socket/stream. This approach is also used in NIO where
an interrupt of a thread blocked on a channel will close the channel and
unblock all waitings threads.
Of course "safely" might mean those other threads being prepared for the
IOException they will get.
If you have access to the socket then you can just close it. If you don't
then you are relying on the library/framework you are using exposing a
> -----Original Message-----
> From: Péter Kovács [mailto:peter.kovacs at chemaxon.hu]
> Sent: Tuesday, 19 December 2006 11:24 PM
> To: dholmes at ieee.org
> Cc: Chirag Shah; Concurrency-interest at cs.oswego.edu
> Subject: Re: [concurrency-interest] Need to kill a single working
> thread, rather than killing the application
> Anyone has an idea/experience how safe it is to close a socket from
> another thread. Are there any utility classes which help me close a
> socket safely?
> David Holmes wrote:
> > Hi,
> > If you are concerned about the socket operation blocking for too long
> > then you can setSOTimeout and if it times out just abandon the
> current task.
> > If more generally you want to cancel a task after N seconds then you
> > need to write the task in a way that is cancellable (which means the
> > socket blocking still needs taking care of) and you need to set up a
> > "watchdog task" to trigger the cancellation. The watchdog task can be a
> > FutureTask submitted to a ScheduledThreadPoolExecutor. But you
> also need
> > to cancel the watchdog if the main task completes normally.
> > Cheers,
> > David Holmes
> > -----Original Message-----
> > *From:* concurrency-interest-bounces at cs.oswego.edu
> > [mailto:concurrency-interest-bounces at cs.oswego.edu]*On Behalf Of
> > *Chirag Shah
> > *Sent:* Saturday, 16 December 2006 9:03 AM
> > *To:* Concurrency-interest at cs.oswego.edu
> > *Subject:* [concurrency-interest] Need to kill a single working
> > thread,rather than killing the application
> > Hi,
> > I am new to TPE. I have a question.
> > I have a Multithreaded Java Application running on SunOS Sparc.
> > Which open a socket connection, get the request and pass it to the
> > worker. The worker will read/write the file and send the data back
> > to the client. Rightnow we have setting of min 300 Thread and max
> > 1000 Thread.
> > My basic requirement is, if a thread takes more than couple of sec
> > eg 5 seconds, I want that thread to stop doing the task, ie
> > terminate that request and start serving other requestm, which is in
> > the queue. b'cos that single task may hung my whole application. I
> > can kill a single request rather than killing the whole application.
> > Would you please give me the best idea?
> > Thanks.
.com/signature-home.htm/1507191490 at Middle5?PARTNER=3>
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
More information about the Concurrency-interest