Tomcat:将会话存储在数据库中

发布于 2024-10-15 07:28:31 字数 1539 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

标点 2024-10-22 07:28:31

如果您不想按照应有的方式使用会话,那么根本不要使用它 - 开发您自己的会话对象。它仍然可以实现 HttpSession,甚至可以从 HttpSession 的实现进行扩展。

您可以使用 Filter 来包装您的请求,以便它返回您的会话对象而不是标准对象。在会话中,您可以将内容存储在数据库中而不是内存中。

您可以使用 Hazelcast,而不是写入数据库 - 它提供分布式集合。但我想这将花费与配置会话复制相同的工作量。会话复制并不是那么困难——所有容器都支持它。

这些是粗略的指导方针,任务并不简单。我建议坚持标准会话使用模式,并且仅在确实需要时才将内容存储在数据库中。

为了避免复制的需要,您可以尝试使用粘性会话 - 即,当负载平衡器将用户定向到服务器时,该用户的每个后续请求都会发送到同一服务器。

If you don't want to use the session in the way it is supposed to be used, then don't use it at all - develop your own session object. It can still implement HttpSession, and even extend from an implementation of HttpSession.

You can use a Filter to wrap your request so that it returns your session object rather than the standard one. In your session you can store things in DB instead of in-memory.

Instead of writing to the DB, you can use Hazelcast - it provides distributed collections. But I guess it will take the same amount of effort as to configure session replication. And session replication is not something that hard - it is supported by all containers.

These are rough guidelines, the task will not be trivial. And I'd recommend sticking to the standard session usage patterns, and storing things in DB only if really needed.

In order to avoid the need of replication you might try using sticky sessions - i.e. when a user is directed to a server by the load balancer, each subsequent request by that user is sent to the same server.

悲凉≈ 2024-10-22 07:28:31

您可能想看看这个项目,我更喜欢将会话存储在memcached 而不是在 DB 中。

You might want to look at this project, I would rather prefer storing sessions in memcached rather than in the DB.

我不会写诗 2024-10-22 07:28:31

在我看来,我自己没有办法实现 JDBC 会话管理器,但是感谢您的回答和时间 - Hazelcast 需要仔细观察,对我来说似乎非常强大。我会做类似 J. Brisbin 的事情: http:// jbrisbin.com/web2/articles/tomcat-session-manager-backed-by-riak/

Seems to me there is no way then implementing an JDBC Session Manager on my own, but thanks for your answers and time - Hazelcast needs some closer look, seems very powerful for me. I will do something similar like J. Brisbin: http://jbrisbin.com/web2/articles/tomcat-session-manager-backed-by-riak/

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