4

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

2 Answers2

3

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?

Community
  • 1
  • 1
M Sach
  • 33,416
  • 76
  • 221
  • 314
  • So this is the exact thing I'm doing right now dear, I keep tracking of the sessions again(beside tomcat does) somewhere. the `HttpSessionListener` is kinda event guy, I want to access the sessions without any specific event sometimes –  Nov 29 '14 at 17:41
0

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.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77