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

General threading problem  RSS feed

 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have written the following function to allow users to submit their data to a web service. The problem is that the progress bar doesn't seem to work and the login dialog does not disappear.
Basically, I think their is something not working with the threading and wondered if anyone had an suggestions or can point out any stupidity:
private void submitDesign()
{
Editor oEditor = this.getActiveEditor();
final Design oDesign = oEditor.getDesignObject();
WebServiceLoginDialog serviceDialog = new WebServiceLoginDialog(mainFrame, "Web Service Login", true);
serviceDialog.show();
if (serviceDialog.getUserResponse() == IResponseType.ACTION_OK)
{
final String sUsername = serviceDialog.getUsername();
final String sPassword = serviceDialog.getPassword();
Runnable rSubmission = new Runnable()
{
public void run()
{
com.informavores.firefly.components.ProgressFrame fProgress = new com.informavores.firefly.components.ProgressFrame("Design Submission", "Please wait while the design is submitted to your hosted service.");
fProgress.show();
String sResult = ServiceData.submitDesign(sUsername, sPassword, oDesign, fProgress);
fProgress.hide();
fProgress.dispose();
Message message = new Message(mainFrame, "Web Service Design Submission", true, sResult);
message.show();
}
};
Thread tSubmission = new Thread(rSubmission);
tSubmission.run();
}
}

Any help if greatly appreciated.
Cheers,
Steve
 
raimondas zemaitis
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
usually you start Thread by calling start(), not run().
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, I think you need start(). If you call run() you're just executing run on the same thread.
When you do get your process running on its own thread, look into SwingUtilities.invokeLater() or invokeAndWait() methods to post progress updates back to the AWT thread. Trying to update Swing controls from another thread gives unpredicatble (and usually undesirable) results.
A design thought ... rather than pass the progress bar as a parameter to the servicing process, look into setting up a listener in the UI that subscribes to data change events from the processor. Any tutorials on Model View Controller (MVC) should have some good examples.
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys, that's very helpful . As you can see, I'm a bit new to threading.
Cheers,
Steve
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!