-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
|> From: Christopher Schultz [mailto:[EMAIL PROTECTED]
|> Subject: Re: retrieving two different objects from session
|> (should be thesame)
|>
|> Silly question.... how do you do this?
|
| Synchronizing on the SessionFacade will suffice for this purpose -
| checking if an attribute exists and then storing it if not.  The
| container insures that accesses to the underlying attribute set itself
| is synchronized (we had a long and somewhat heated discussion about the
| necessity of that a couple of years ago).

Okay, cool. I just assumed that

HttpSession session = request.getSession();
Object myObject;
synchroinzed(session) {
~ myObject = session.getAttribute("myObject");

~ if(null == myObject)
~ {
~   myObject = // get new object

~   session.setAttribute("myObject", myObject);
~ }
}

could not be considered threadsafe. Fortunately, I have never had to
write code such as this :)

Can you explain how this is done? My tenuous understanding of session
handling in Tomcat is that HttpServletRequest.getSession roughly returns:

new StandardSessionFacade(theRealSessionObject)

...which means that the "real" session is hidden behind the facade
(makes sense), but that the object implementing the session is therefore
unavailable for synchronization purposes. Since synchronized() isn't a
function call, it can't be virtualized and/or intercepted, so wrapping
the session in a facade actually eliminates the possibility for
synchronization.

I must have this wrong. It's tough to sit down with the code and figure
everything out, though. :(

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgjFVMACgkQ9CaO5/Lv0PBhzgCfZrQkFsf4C7LU9ABWo7RxXjQ1
0h0An0C3RKWSEIVSOVdaJqf9qugcJ/31
=RZ9f
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to