• 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

GUI and lock(record)!

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I have implemented a LockManager and it works fine.
But while one client holds the lock on a record and the other is waiting to obtain the lock on the same record the GUI of the waiting client is not responsive. Exactly, minimizing the waiting client window and then maximizing the window only the empty frame is shown and the GUI is not rendered. After releasing the lock the waiting client is rendered and gets the lock.
How to avoid this behavior?
I don't think that it is acceptable, isn't it?
Kind regards
Jochen
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jochen van Waasen:
But while one client holds the lock on a record and the other is waiting to obtain the lock on the same record the GUI of the waiting client is not responsive. [...] How to avoid this behavior?

This is a common problem in Swing applications. Swing is not threadsafe and all Swing code executes in a single thread, the event dispatch thread. By making your database calls in the event dispatch thread, you can freeze the entire GUI. The solution is to move such operations out of the event dispatch thread and using worker threads to handle them. The Swing trail has quite a bit of information about it.
Worker threads are an everyday part of Swing application development. I did use worker threads and passed fine. I understand (but please correct me, Mark) that Mark did not use worker threads and passed fine too. So it's up to you really. The GUI feels slicker if it remains alive when a database call blocks, but if you're pressed for time or simply not very comfortable with threads it may be wiser to cop out.
- Peter
[ February 06, 2003: Message edited by: Peter den Haan ]
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well there are ways to spawn a new thread to handle your booking and keeping the GUI refreshed.
However, you don't need to do that in the assignment.
My GUI waited till the locking and booking then unlocking was doen before refreshing and did not lose any points.
Mark
 
Whatever you say buddy! And I believe this tiny ad too:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic