• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads  RSS feed

 
Chandramouli V.N
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I hava an application which updates and retrieves data from a database.
I have written an class to save and retrieve data from a database.The methods in the class are static synchronized methods.I have written a seperate class for the GUI.When I call the synchronized methods from the GUI class do I have to do anything? or is it enough I just call the method.

Thanks
Mouli
 
Frank Ertl
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should put the call to the db-access-methods in an extra thread, because otherwise your GUI will freeze.
You also should make shure that the db-access-methods don't call each other or you may run into a deadlock.
 
Chandramouli V.N
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply..
I could understand the second line but not the first.(Meaning of freeze)..

Thanks

Mouli
 
Frank Ertl
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that if you call the db directly from, let's say, your ActionListener, then the call will be handled inside the AWT-thread. So nothing will work until the call returns. If the db-connection is slow or an entry is locked your GUI will "freeze" what means it won't react to anything.
So you should start your own thread for calling the db.
 
Chandramouli V.N
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frank

Mouli
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Specifically it means that the AWT thread will be busy getting data from the db and won't be doing its job which is updating the screen and reading the keyboard/mouse inputs, etc. So your program will appear to be 'frozen' until the db call finishes.

So you spawn a seperate thread to give your program 'responsiveness.'
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, once you have the database result if you need to update your GUI it should be done in the Event Handling Thread. You can use SwingUtilities.invokeLater() for this purpose. Very little in AWT/Swing is thread-safe, so be very careful about what you call from a different Thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!