Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to stop Threads
- From: mpoulin@xxxxxxxxxxxxxxxxx (Maxime Poulin)
- Subject: How to stop Threads
- Date: Tue, 29 Feb 2000 09:27:46 -0500
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01BF82C2.A60B70C0
Content-Type: text/plain;
charset="iso-8859-1"
A clean way would be to have a bRun boolean set somewhere and you could use
it like this :
boolean bRun;
public void run()
{
while(this.bRun)
{
...
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals(START_BUTTON_ACTION_COMMAND)
{
this.bRun = true;
(new Thread(this)).start();
}
else if (e.getActionCommand().equals(STOP_BUTTON_ACTION_COMMAND)
this.bRun = false;
}
This way, you thread will die naturally.
> -----Original Message-----
> From: hari [mailto:harishreddy@xxxxxxx]
> Sent: Tuesday, February 29, 2000 12:00 PM
> To: advanced-java@xxxxxxxxxxxxxxxx
> Subject: How to stop Threads
>
>
> Hi All,
>
> How do we stop thread once it is started ?
>
> The thread is started in the actionevent method, and it
> displays the status of
> the thhread processing.
> On the cancel button press of the dialog I want the the thread to be
> stop the processing and exit from the run method.
> Any pointers on this .
>
>
> Thanks in ADVANCE.
> HARI
>
> ____________________________________________________________________
> Get free email and a permanent address at
http://www.netaddress.com/?N=1
---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
------_=_NextPart_001_01BF82C2.A60B70C0
Content-Type: text/html;
charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2650.12">
<TITLE>RE: How to stop Threads</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>A clean way would be to have a bRun boolean set somewhere and you could use it like this :</FONT>
</P>
<P><FONT SIZE=2>boolean bRun;</FONT>
</P>
<P><FONT SIZE=2>public void run()</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR> <FONT SIZE=2>while(this.bRun)</FONT>
<BR> <FONT SIZE=2>{</FONT>
<BR> <FONT SIZE=2>...</FONT>
<BR> <FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>public void actionPerformed(ActionEvent e)</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR> <FONT SIZE=2>if (e.getActionCommand().equals(START_BUTTON_ACTION_COMMAND)</FONT>
<BR> <FONT SIZE=2>{</FONT>
<BR> <FONT SIZE=2>this.bRun = true;</FONT>
<BR> <FONT SIZE=2>(new Thread(this)).start();</FONT>
<BR> <FONT SIZE=2>}</FONT>
</P>
<P> <FONT SIZE=2>else if (e.getActionCommand().equals(STOP_BUTTON_ACTION_COMMAND)</FONT>
<BR> <FONT SIZE=2>this.bRun = false;</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>This way, you thread will die naturally.</FONT>
</P>
<P><FONT SIZE=2>> -----Original Message-----</FONT>
<BR><FONT SIZE=2>> From: hari [<A HREF="mailto:harishreddy@xxxxxxx">mailto:harishreddy@xxxxxxx</A>]</FONT>
<BR><FONT SIZE=2>> Sent: Tuesday, February 29, 2000 12:00 PM</FONT>
<BR><FONT SIZE=2>> To: advanced-java@xxxxxxxxxxxxxxxx</FONT>
<BR><FONT SIZE=2>> Subject: How to stop Threads</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Hi All,</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> How do we stop thread once it is started ?</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> The thread is started in the actionevent method, and it </FONT>
<BR><FONT SIZE=2>> displays the status of</FONT>
<BR><FONT SIZE=2>> the thhread processing.</FONT>
<BR><FONT SIZE=2>> On the cancel button press of the dialog I want the the thread to be </FONT>
<BR><FONT SIZE=2>> stop the processing and exit from the run method.</FONT>
<BR><FONT SIZE=2>> Any pointers on this .</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Thanks in ADVANCE.</FONT>
<BR><FONT SIZE=2>> HARI</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> ____________________________________________________________________</FONT>
<BR><FONT SIZE=2>> Get free email and a permanent address at </FONT>
<BR><FONT SIZE=2><A HREF="http://www.netaddress.com/?N=1" TARGET="_blank">http://www.netaddress.com/?N=1</A></FONT>
</P>
<P><FONT SIZE=2>---</FONT>
<BR><FONT SIZE=2>To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx</FONT>
<BR><FONT SIZE=2>To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01BF82C2.A60B70C0--
---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
- Follow-Ups:
- How to stop Threads
- From: Vincent Cheesbrough
- How to stop Threads
- Prev by Date: Cryptography and Encryption
- Next by Date: JNI char * in c -- to -- jcharArray to -- char[] in Java
- Previous by thread: How to stop Threads
- Next by thread: How to stop Threads
- Index(es):