如何通过 Spring 在 Hibernate 中使用 ThreadLocal
目前,我们对 Swing 客户端/服务器应用程序使用 Hibernate/Spring 的每个操作(反)模式一个会话。应用程序不断增长,请求变得越来越复杂,这导致了性能问题。因此,我们决定对复杂请求重用会话,这需要对数据库执行更多请求。
我们被告知,ThreadLocal 会话模式可能有助于实现此目标。我们读到了它,它似乎非常适合,但我也听说 Spring 可以自己处理 ThreadLocals。不幸的是,我无法确认此信息,也没有找到任何有关它的有用信息。由于我对此有点陌生,我可能会搜索错误的关键字。
有没有人对这个用例有任何经验,并且知道在什么情况下我可以找到更多有关它的信息?或者我们是否必须自己注意何时打开/关闭会话?感谢您的帮助!
问候, 伊梅内
Currently we use a session per Operation (anti-) Pattern with Hibernate/Spring for our Swing client/server application. The application grew and requests got more and more complex, which resulted in bad performance issues. Because of that, we decided to reuse the session for complex requests, which need to perform more requests on the database.
We have been told that the ThreadLocal Session Pattern might be useful to achieve this aim. We read about it, and it seems to perfectly fit, but I also heard, that Spring can handle ThreadLocals by itself. Unfortunately I wasn’t able to confirm this information and didn’t found any helpful information about it yet. Since I am kinda new to this, I might search for the wrong keywords.
Has anyone any experiences concerning this use case and knows in which context I might find more information about it? Or do we have to take care on when to open/close sessions ourselves? Thanks for any help!
Greets,
ymene
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许此回复在论坛主题 可能会对您有所帮助。
Maybe this reply on a forum topic on Spring Community site may help you.