user2889419
user2889419

Reputation:

How to access tomcat session context?

I'm using tomcat8 and I like to look through the available sessions and invalidate/alter some sessions in my servlet
Currently I keep every sessions in my own context(Vector) and I believe it's not a good idea.
So how may I access tomcat session management/context to do so?
Thanks

Upvotes: 4

Views: 2089

Answers (2)

Christopher Schultz
Christopher Schultz

Reputation: 20837

You can use JMX to look into Tomcat's internals, including the current list of sessions. Use jvisualvm to connect to a running Tomcat and look-around for the interesting data.

Then use the JMX API to connect to the (in-process) JMX server from your application and find the (Session) Manager bean to get everything.

Upvotes: 0

M Sach
M Sach

Reputation: 34424

I think your looking for HttpSessionListener.You can hold of sessions all with help of this. Thats the most cleaner way i can think of.

See below examples

How to easily implement "who is online" in Grails or Java Application?

How can i load Java HttpSession from JSESSIONID?

Upvotes: 3

Related Questions