This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Stopping multi-thread Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Stopping multi-thread" Watch "Stopping multi-thread" New topic
Author

Stopping multi-thread

Derek Bright
Greenhorn

Joined: Aug 28, 2008
Posts: 28
Hi, i am currently doing a project sort of like a webcrawler. I have a problem in stopping the process after meeting certain criteria. Initially i used system.exit(). But i intend to implement JFrame to run my program, so using system.exit() will also exit the JFrame itself.

I did some research online, but i still can't really stop the thread. Knowing that stop() is depreciated, how else can i stop, i am still trying to use the while(status), but doesn't seems to work for me.

Thanks~
Derek Bright
Greenhorn

Joined: Aug 28, 2008
Posts: 28
probably to add on a bit, my code is something like this

private volatile boolean stopCrawling;


while(!stopCrawling){
.
.
.
}

even if the stopCrawling eventually becomes true, the thread continues to run...why is it so?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3090
    
    5

How do you know that the thread keeps running even though the stopCrawling flag is set to false?

To diagnose your problem we will need to see more code. Preferably make a complete, small, self contained version of the application that we could copy and compile ourselves and which shows your problem. Without context we can't really help.

An example of a SSCCE that could be used as an example for your work would be:


Of course, this will look nothing like your code (probably). But the idea is to simplify your task as much as possible, take out all the code not explicitly related to the problem, and show us the gist of the issue.


Steve
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Stopping multi-thread
 
Similar Threads
stopping the thread
if thread dies finally won't execute
Tomcat stopping problem
Not able to resume command promt after using swings
Stopping a thread