Win a copy of Terraform in Action this week in the Cloud forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic