Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

abort a method  RSS feed

 
Ivn Tcakov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I was wondering if anyone knows how I can abort a method that is runing and taking too long to finish.
I need to do it so that a user can abort it by pushing on a button in a pop-up window. So, how do I actually get into that method and make it stop? The long loops inside the method are usually stopped by calling 'break' but that is inside of the method. I need to do it from "outside".
One thing I tried was to have a global boolean value called 'abort' that is set to false and then in the loops of the method I check for its value. So when the user presses the abort button, I make the boolean value true, hoping that then the loops would start 'seing' it as false and break. It didn't happen... I guess the method just had to finish before any values that are called outside of it can change.

Any suggestions or comments?
I would greately appreciate help.
Thanks
Ivan
 
Petr Blahos
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have the right idea, but you must run your method in a thread.
The best thing to do is probably to google for: java swing threads and
read whatever you have found on java.sun.com. If you only have one
thread and are running the method in an event handler, you
button-pressed event will be processed AFTER the method finishes. But
it sort of isn't visible from your description.

P.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!