You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Peter Mutsaers <pe...@mutsaers.com> on 2003/04/09 10:10:37 UTC

HttpSession instance is differenct for each new request!

Until recently we used the session object in order to synchronize some
blocks on:

synchronized ( request.getSession() ) { ... }

Yesterday I found out that each time you call request.getSession(),
tomcat/catalina returns another instance of SessionFacade. Each
instance represents the same session (getAttribute and getId return
the same values each time) but still it is very unfortunate and
questinable that a different object is returned each time (causing
synchronization on the session object to break).

Is this normal, should not the same object be returned every time? Has
it maybe been fixed in newer tomcat versions (we are still using
4.0.3)?

Now I have to go through great lengths in order to create a unique
Object as session-attribute to synchronzie on instead:

synchronized ( request.getSession().getAttribute("theSyncObject") )

Initially creating this attribute needs to be synchronized on the
session as well, creating a chicken and egg problem :) Now I was
forced to synchronize this step on the application (on some basic
Class object).


-- 
Peter Mutsaers, Dübendorf, Switzerland.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org