• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI and lock(record)!

 
Jochen van Waasen
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
 
Peter den Haan
author
Ranch Hand
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 ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic