• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mansoor Akhtar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5136
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic