File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes General threading problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "General threading problem" Watch "General threading problem" New topic
Author

General threading problem

Steve Wood
Ranch Hand

Joined: Jan 08, 2003
Posts: 137
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

Joined: Feb 23, 2001
Posts: 104
usually you start Thread by calling start(), not run().
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Steve Wood
Ranch Hand

Joined: Jan 08, 2003
Posts: 137
Thanks a lot guys, that's very helpful . As you can see, I'm a bit new to threading.
Cheers,
Steve
 
IntelliJ Java IDE
 
subject: General threading problem
 
Threads others viewed
Database connection problem
Bean New class wont compile
SOAP validateUser
Need an attribute to be available in different places (SOLVED)
Axis - Server.userException
MyEclipse, The Clear Choice