If I understand correctly we are discussing in wrong direction.
The question originally asked here is:
Is it possible to share a session variable across two different applications?
The question does not talks about multiple JVM, but multiple applications.
My answer to both questions (multiple applications, multiple JVMs) is YES.
Yes we can share the same session across multiple web applications and multiple JVMs as long as we are able to pass through session token across.
response.sendRedirect(response.encodeRedirectURL("http://someapp.com/someResourceAbsoluteURL"))
can be used to pass through the session id to different applications. And if cookies are enabled, and session tracking is being done using cookie, then url encoding is not reqquired, browser automatically attaches the cookie with request before sending to same/another application as long as application shares the same domain, i.e.
http://app1.mycompany.com/App1/servlet1 and
http://app2.mycompany.com/App2/servlet2 can share the same cookie, both applications would have to set the domain of cookie to "mycompany.com" in order to share the cookie across multiple applications.
Another point mentioned here was:
Session level variables are not even accessible to other users in the same application. Then it is not possible to access it out side the application.
This is incorrect. A user may navigate to different application from the same browser and the two application can talk to each other in user's context i.e. session. For example multiple applications of same company requiring "single sign-on"!
Now, coming to sharing session across JVMs, yes it can be done. We can passivate the session and activate it on other JVMs by making all our session attributes serializable. All this happens automatically by using HttpSessionActivationListener as Sumit / Narendra mentioned.
Hope this helps.
[ July 05, 2005: Message edited by: Anand Wadhwani ]