Link to home
Start Free TrialLog in
Avatar of NetWize
NetWize

asked on

Can I rely on Session-Timeout to call valueUnbound() ?

I read the servlet specs 2.2 - 2.4, but I'm unsure if it's required for a Container to unbind all values of a session when invalidating it as a result of a session timeout. (that is: valueUnbound() will be called)

I tested that with tomcat 4.1.18 and it works, but can I rely on this in terms that it is a required behaivor?

Thanks,

Jan
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

It seems that according to the spec, YES, valueUnbound() SHOULD be called.

If it is not...it is a bug in the container, and there's no accounting for that :-(
How can my application get to know when a HttpSession is removed (when it time- outs)?

Define a class, say SessionTimeoutNotifier, that implements
javax.servlet.http.HttpSessionBindingListener. Create a SessionTimeoutNotifier object and add it to the user session. When the session is removed, SessionTimeoutNotifier.valueUnbound() will be called by the servlet engine. You can implement valueUnbound() to do whatever you want.

[from http://trinetra.ncb.ernet.in/~chandu/resources/Java/JSPFAQ.pdf]
Avatar of NetWize
NetWize

ASKER

Thank's so far, but it gets even worse:

Do I have any chance to let the container inform me of the session invalidation within a given timeframe?
I noticed that the actual removal takes longer than the value passed to setMaxInactiveInterval(). So this will depend on how the server checks invalid sessions and that doesn't suite my needs i think.
Or are these checks required to be done in a given time?
ASKER CERTIFIED SOLUTION
Avatar of DynaPete
DynaPete

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NetWize

ASKER

Ok, that's good to know.

What Application-Servers are covered by that experience? My webapp should at least run on timcat, jboss (these i tested myself), weblogic 5 to 7 and websphere.
Avatar of NetWize

ASKER

Ah and test result showed that a 2-minute timeout took from 2:10 to 3:30 wich is not good but acceptable.
Yay!  Timcat! ;-)

Java is not a Real Time Language, you can only suggest when things should timeout, not enforce it :-/  People are working on a Real Time JVM, but I wouldn't hold your breath...

As Tomcat and JBoss are free, and Weblogic and Websphere cost cash, I would expect it to work on all of them...  if not, by buying a copy of the other two (which someone will have to do to test it), I assume you will have the right to ask them why not! :-)
PS:  DynaPete should get the points for this Q :-)

He has had experience, I just cut and paste the web ;-)
Avatar of NetWize

ASKER

Thank you, I feel much better now removing the timeout-threads that someone inserted into the program long time ago and that didn't work properly...