aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Java's call to backend with sql, halts the frontend GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java Watch "Java New topic
Author

Java's call to backend with sql, halts the frontend GUI

Mansoor Akhtar
Greenhorn

Joined: Jul 11, 2010
Posts: 12
Hi,

When I call the backend with sql for fetching/updating data, the frontend becomes unresponsive until the backend call is returned and the JVM queues all the events in that time to be processed afterwards. Can some one please suggest a way to counter this situation.
Although logically the application should not do anything until the call is returned, however for that matter, I want to disable some buttons and refresh a JLabel saying "processing... Please wait", but the JVM, is trying to be over-smart and deferring these repainting/events until after the backend call returns. Of course, I am performing the gui changes before making the backend call.

Thanks.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

the JVM, is trying to be over-smart and deferring these repainting/events until after the backend call returns.

Don't blame the JVM for your own lack of understanding ;)

Of course, I am performing the gui changes before making the backend call.

... and then keeping the EDT too busy to repaint the GUI. Recommended reading:
http://download.oracle.com/javase/tutorial/uiswing/concurrency/index.html


luck, db
There are no new questions, but there may be new answers.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Darryl is correct -- the JVM is acting correctly in this situation and when you study a bit more into concurrency and Swing you will see why. Please read the tutorial that was linked to in Darryl's helpful post for the gory details, but in a nutshell, you'll need to do all of your time / cpu -intensive processing off of the Swing thread and in a background thread, but at the same time take care to make Swing calls on the main Swing thread, the EDT. And while it may sound complex now, like anything else, the more work and struggling you do with this type of problem, the easier it will get for you.

Luck!
Mansoor Akhtar
Greenhorn

Joined: Jul 11, 2010
Posts: 12
Thanks a lot Darryl. I am no more blaming the JVM for my "own lack of understanding" ... ;)
Pete, thanks for the reply.
The problem is solved by using the SwingWorker.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Mansoor Akhtar wrote:Thanks a lot Darryl. I am no more blaming the JVM for my "own lack of understanding" ... ;)
Pete, thanks for the reply.
The problem is solved by using the SwingWorker.


Glad you've got things working out! Please let us know how the whole project turns out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java's call to backend with sql, halts the frontend GUI