Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing issues  RSS feed

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read quite alot about hibernate causing problems with swing, mainly due to the swing event model and threading.

Can someone explain this to me in "laymans" terms ? Im an advanced java developer, but I don't understand why or how it could be that hibernate make multiple sessions because of the Swing architecture.

In particular, I wonder - why would hibernate even have access or knowledge of swings architecture or threading to begin with.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't seen those discussions (but would be interested if you could point to them). I would imagine that they go back to the fact that in Swing, processing that takes more than a short time to finish should not be done in the GUI thread (which is the one that runs GUI listeners). So for DB access (presumably a not-so-short process) you should start its own thread with its own Session.

Since control returns to the GUI after the worker thread starts, that means that a user could start another thread doing DB stuff before the first one finishes, thus potentially leading to concurrency problems. Not a problem for read-only operations, but something to think about for transactions.

One way around this is would be to disable parts of the GUI that could cause problems while a transaction is running, or to run transactions from the main GUI thread (which means that the complete becomes unresponsive to any user actions).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!