• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

General threading problem

 
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
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
usually you start Thread by calling start(), not run().
 
(instanceof Sidekick)
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
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic