We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
如果您不想按照应有的方式使用会话,那么根本不要使用它 - 开发您自己的会话对象。它仍然可以实现
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 ofHttpSession
.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.
您可能想看看这个项目,我更喜欢将会话存储在memcached 而不是在 DB 中。
You might want to look at this project, I would rather prefer storing sessions in memcached rather than in the DB.
在我看来,我自己没有办法实现 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/