🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8605

Re: Killing a blocked thread...

#8605
From: Torsten Welches
Date: Sun, 11 Mar 2001 20:53
67 lines
3138 bytes
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: <3aabe6be_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!newsfeed.direct.ca!look.ca!hub.org!hub.org!PeerFeed.KWeb.on.ca!bornews.borland.com!dnews!195.14.251.254
References: <98gdng$3s62@bornews.inprise.com>

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-11 13:04:07 PST
From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Newsgroups: borland.public.jbuilder.java.language
References: <98gdng$3s62@bornews.inprise.com>
Subject: Re: Killing a blocked thread...
Date: Sun, 11 Mar 2001 21:53:31 +0100
Lines: 69
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
NNTP-Posting-Host: 195.14.251.254
Message-ID: <3aabe6be_1@dnews>
X-Trace: 11 Mar 2001 12:57:34 -0800, 195.14.251.254
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!newsfeed.direct.ca!look.ca!hub.org!hub.org!PeerFeed.KWeb.on.ca!bornews.borland.com!dnews!195.14.251.254