如何通过 Spring 在 Hibernate 中使用 ThreadLocal

发布于 2024-09-18 09:06:04 字数 361 浏览 5 评论 0原文

目前,我们对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诠释孤独 2024-09-25 09:06:04

也许此回复论坛主题 可能会对您有所帮助。

Maybe this reply on a forum topic on Spring Community site may help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文