Session management using Hibernate in a *multi-threaded* Swing application

前端 未结 3 1638
耶瑟儿~
耶瑟儿~ 2021-02-09 10:11

I\'m currently working on a (rather large) pet project of mine , a Swing application that by it\'s very nature needs to be multi-threaded. Almost all user interactions might fet

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-09 10:59

    Don't expose the Session itself in your data API. You can still do it lazily, just make sure that the hydration is being done from the 'data' thread each time. You could use a block (runnable or some kind of command class is probably the best Java can do for you here unfortunately) that's wrapped by code that performs the load async from the 'data' thread. When you're in UI code, (on the UI thread of course) field some kind of a 'data is ready' event that is posted by the data service. You can then get the data from the event use in the UI.

提交回复
热议问题