Tomcat: Saving a Session in a Database

I am looking for a way to avoid replication / clustering in memory in memory and keep the session in the database. Using Tomcat JDBCStore is useless at the moment, because it stores inactive sessions in the database to save server memory. Any suggestions?

Thanks in advance Fabian

+7
java tomcat jdbc servlets replication
Jan 31 '11 at 9:27 a.m.
source share
3 answers

If you do not want to use the session as intended, it should be used, then do not use it at all - create your own session object. It can still implement HttpSession and even extend from the implementation of HttpSession .

You can use Filter to transfer your request so that it returns a session object, not a standard one. In your session, you can store things in the database, not in memory.

Instead of writing to the database, you can use Hazelcast - it provides distributed collections. But I think it will take as much effort as setting up session replication. Session replication is not difficult — it is supported by all containers.

These are rough recommendations; the task will not be trivial. And I would recommend sticking to standard session usage patterns and storing things in the database only if necessary.

To avoid the need for replication, you can try using sticky sessions — that is, when a user is redirected to a server using a load balancer, each subsequent request from that user is sent to the same server.

+5
Jan 31 2018-11-21T00:
source share

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

+3
Jan 31 '11 at 10:50
source share

It seems to me that I will not implement the JDBC Session Manager myself, but thanks for your answers and time - Hazelcast needs a closer look, it seems very powerful to me. I will do something similar, e.g. J. Brisbin: http://jbrisbin.com/web2/articles/tomcat-session-manager-backed-by-riak/

0
04 Feb '11 at 9:30
source share



All Articles