• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread never exits  RSS feed

 
Bill Gunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm running a thread that gathers info, but when it finishes (or user presses stop), I'd like to exit and run some final code then display a dialog that everything is finished. I cannot get this to happen despite my best efforts. My code structure looks something like this:


What I end up with is the program going between run and the while loop when it finishes. I press the button and everything stops, but it never returns to the actionlistener method so I can execute other code.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bill Gunn:
[QB]but it never returns to the actionlistener method so I can execute other code.


Which actionlistener method?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't fully understand how and when the thread is started and stopped, but the usual approach would be to introduce a boolean, which is set in your event handler, and checked in the while-condition. That way you can stop the tread loop whenever a relevant user event has happened.
 
Bill Gunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
right, and I have set that up, and it works. If I press the stop button, it toggles a boolean and the thread stops. The actionlistener this is all called from is a start button. But, when the loop finishes (when there is no it.Next()), I'd like it to exit the thread perform some cleanup, and report to the user. I have put system.out.println's throughout the program, and they all seem to print to the command line before or during the loop happening. I can't find a single place where it will only execute once the loop is finished, without pressing the stop button.

[ August 18, 2006: Message edited by: Bill Gunn ]
[ August 18, 2006: Message edited by: Bill Gunn ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should probably take a look at https://swingworker.dev.java.net/
 
Bill Gunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that looks perfect, thanks.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!