Article View: borland.public.jbuilder.java.language
Article #8621Re: Killing a blocked thread...
From: Kashif Dastgir
Date: Mon, 12 Mar 2001 15:31
Date: Mon, 12 Mar 2001 15:31
79 lines
3692 bytes
3692 bytes
Thanks Torsten,
Atleast it'll help me to handle the situations where i do have access to I/O
device of the input class, if not everywhere. However, it seems to be a very
trivial and common thing, and i'm rather surprised that there doesn't seem
to be a way out.
Thanks anyways... and regards!
Kashif
"Torsten Welches" <torsten.welches@who.cares.netcologne.de> wrote in message
news:3aabe6be_1@dnews...
Kashif,
the "official" way to go is Thread.interrupt() but odds are that your Input
blackbox class uses InputStream blocking i/o that does not care about
interrupts. If you had access to the Input's i/o device (e.g. Socket) you
could simply close this to force an IOException. If Input does not provide
it your stuck I guess.
Torsten
Kashif Dastgir schrieb in Nachricht <98gdng$3s62@bornews.inprise.com>...
>Hello
>
>I'm having a problem at hand related to killing a thread that is currently
>waiting for return from a blocking call of some other class... The code is
>something like...
>
>class MyThread extends Thread
>{
> private Input input = null;
> private boolean keepRunning = true;
>
> MyThread (Input input) throws Exception
> {
> if (input == null) throw new Exception("Null arguments");
>
> this.input = input;
> }
>
> public run ()
> {
> while (keepRunning)
> {
> String str = input.getInput(); // a blocking method call
> // Some other code
> }
> }
>
> public kill ()
> {
> this.keepRunning = false;
> }
>}
>
>In the code, the class Input is an external class and it's code is not
>available. We are making a call to the getInput() method which is blocking,
>and it wont return unless there is some input available inside the input
>object. Now assuming that the input object passed to the constructor is a
>shared object in the system and getInput() is a synchronized method. This
>implies that apart from my thread, there can be many other threards using
>the same object.
>
>Now I just want to kill my thread (cuz i'm no longer interesting in getting
>any input from the input object). However, the input object being a shared
>object will stay and the other threads in the system will still keep
waiting
>for an input from that object. I just want to kill MY thread. How can i do
>that. In the above example, i can call the kill() method of my thread which
>will set the loop invariant to false, but it wont help unless the function
>call from the blocking method is returned, and the loop invariant will only
>be checked afterwards. Is there a way to get the control back from a
>blocking call.
>
>Regards
>Kashif
>
>
Technical Details
Message-ID:
<98iq5v$bdc6@bornews.inprise.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!news-out-sjo.usenetserver.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!not-for-mailReferences:
<98gdng$3s62@bornews.inprise.com> <3aabe6be_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,ce7e5a0605d83b15 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-03-12 07:44:07 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!news-out-sjo.usenetserver.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!not-for-mail From: "Kashif Dastgir" <kdastgir@yahoo.com> Newsgroups: borland.public.jbuilder.java.language Subject: Re: Killing a blocked thread... Date: Mon, 12 Mar 2001 20:31:19 +0500 Organization: Another Netscape Collabra Server User Lines: 83 Message-ID: <98iq5v$bdc6@bornews.inprise.com> References: <98gdng$3s62@bornews.inprise.com> <3aabe6be_1@dnews> NNTP-Posting-Host: 203.135.14.130 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200