Article View: borland.public.jbuilder.java.language
Article #17388Re: Threads
From: mariano podesta
Date: Tue, 17 Nov 1998 00:00
Date: Tue, 17 Nov 1998 00:00
58 lines
1887 bytes
1887 bytes
using Thread.stop() is a bad thing!
try to use a boolean field (like private boolean mustExit) to verify in
your run()s main loop like
public void run()
{
while (!mustExit)
{
<your code here> // thread is processing
}
<more code> // thread is out!
}
i made a simple tetris and i use 2 threads and i think that this way
(boolean field) is the best.
send me an e-mail if you want to see it (tetris with code if you like).
bye.
Vladimir Olenin wrote:
> Hi,
>
> I hava the following:
>
> public class Connection extens Thread{
>
> public Connection(){
> .....
>
> this.start();
> }
>
> public void run(){
> .....
> }
>
> public void closeConnection(){
> .....
>
> if(this.isAlive()) // THE PROGRAM
> this.stop(); // HANGS HERE !!!
> }
> }
>
> When i try to stop the thread, the program just hangs. I suppose it's a
> problem of synchronization. Any help at all would be very appreciated.
> It'd be great to have an example or link to some tutorial concerning
> threads.
>
> Vladimir
>
> --
> >~~~~~~~~<=============>~~~~~~~~<
> Be yourself no matter what they say...
> Join in Java community now!
> http://www.geocities.com/SiliconValley/Heights/9815
> >~~~~~~~~<=============>~~~~~~~~<
Technical Details
Message-ID:
<3651927C.AD1C9CED@netscape.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<365078D0.6AC9F125@collegemail.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,193974b4bf6e2907 X-Google-Attributes: gidf74b3,public From: mariano podesta <marianop@netscape.net> Subject: Re: Threads Date: 1998/11/17 Message-ID: <3651927C.AD1C9CED@netscape.net> X-Deja-AN: 412649478 Content-Transfer-Encoding: 7bit References: <365078D0.6AC9F125@collegemail.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language