Okay, new to Swing. I am moving a command line application to Swing and want to manage a processing loop (stopping and starting it.) On startup the application kicks the process off and I will stop it or restart it. The stop was easy from what I can tell but I can't get the process to restart (processTestLoop.)
Here is the code sample that I am testing (sorry for the length.) Any thoughts?
You've got a Swing concurrency issue, plain and simple. Bottom line is, when you call Thread.sleep(...) on the main Swing thread, the EDT, you prevent Swing from painting or interacting with the user, so that while the loops still runs, your program appears to grind to a halt. The solution -- use a background thread. For instance you could use a simple background thread like so:
Thanks for your pointers. The testLoop field in the actual program is different, I was trying to build a test framework to make sure what track I was on. Should I make the boolean field and the stop/start methods synchronized? Other than those I do not share information.
I am reading up on SwingWorkers now. Just trying to avoid rewriting the command line program and seeing if I can fit it in. Though I may be better off rewriting portions of the logic to fit better.