Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Stopping multi-thread  RSS feed

 
Derek Bright
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!