stopping a thread
ok i've got a problem stopping a thread...
this thread runs a recursive function... and while it is running the function... i want to stop it...
i've tried threadPointer = null; but it doesn't work.. the thread still continues running...
any suggestions??
TIA
[310 byte] By [
icube] at [2007-11-11 9:58:32]

# 2 Re: stopping a thread
do you mean thread.stop(); which will terminate the execution of a thread.If you going to use the thread again i think you should call thread.suspend(); instead then thread.resume(); to start it again
dojo at 2007-11-11 22:33:05 >

# 3 Re: stopping a thread
do you mean thread.stop(); which will terminate the execution of a thread.If you going to use the thread again i think you should call thread.suspend(); instead then thread.resume(); to start it again
i believe the methods u mentioned are deprecated...
Where is the thread?
the thread executes a recursive function.. this function is working correctly... no problems... i just want to end it manually...
here is what i tried... i tried to use an exit flag to return back all the recursive function... which still doesn't work
class A extends thread{
boolean exit = false;
recursive_fn(argument){
if(exit){return;}
...
recursive_fn(argument);
}
}
main(){
A a = new A();
a.start();
}
button_pressed(){
a.exit = true;
}
icube at 2007-11-11 22:34:15 >

# 4 Re: stopping a thread
if you want to end it manually you have the right idea.
public class Recurse extends Thread{
boolean running = false;
public Recurse(){
// constructor stuff here
this.start();
}
public void run(){
running = true;
while(running){
//your code here
}
public void halt(){
running = false;}
}
this will run the loop till the halt method is called causing the flag to be set to false. The stop() method should not be used because it stops the execution immediately and may result in data corruption and general messiness.
# 6 Re: stopping a thread
Which method isn't working? The recursive or the run method? If your trying to get the thread to run a recursive method the output of the method needs to be handled in the run method or you need to pass an argument to the run method with an object from your calling thread to "capture" the output.
Just to make sure you realize you need to call halt() in order to stop the thread.
# 7 Re: stopping a thread
Which method isn't working? The recursive or the run method? If your trying to get the thread to run a recursive method the output of the method needs to be handled in the run method or you need to pass an argument to the run method with an object from your calling thread to "capture" the output.
Just to make sure you realize you need to call halt() in order to stop the thread.
i think u misunderstood me... i've already started the thread successfully... my problem is i can't STOP the thread while it is running as written in the thread title, the code i wrote above is how i tried to stop it but it din't, the recursive function still continues running.
icube at 2007-11-11 22:38:15 >
