aspose file tools*
The moose likes Servlets and the fly likes session behavior in distributed environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "session behavior in distributed environment" Watch "session behavior in distributed environment" New topic
Author

session behavior in distributed environment

Calvin Kong
Ranch Hand

Joined: Jul 02, 2003
Posts: 37
Hi,

I have a question regarding session behavior in distributed environment. Say I have 2 servers in clusters. If inside the servlet, the application call session.invalidate() method right after the session is move from server A to server B, what will happen? Also, any session attribute that's not implementing java.io.Serializable will not be migrated. Does it mean I'll get null value if I call session.getAttribute("XXX") when the session is moved to server B where the attribute is set when the session is in server A? Does the behavior depend on server? (we are using JRun)

Thanks

Calvin

[ January 21, 2005: Message edited by: Calvin Kong ]
[ January 21, 2005: Message edited by: Calvin Kong ]

Cal<br />SCJP,SCWCD,SCBCD
sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
the application call session.invalidate() method right after the

The session will be invalidated and that session object is ready for GC.

Also, any session attribute that's not implementing java.io.Serializable will not be migrated

It depends upon the container implementation. If the attribute it not serialized you will get null after the migration of session. Actually some container may throw error if attribute is not serialized(but i am not very sure about it). Lets wait for the reply from other guys.

Hope that helps.


Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30752
    
156

Originally posted by Calvin Kong:
If inside the servlet, the application call session.invalidate() method right after the session is move from server A to server B, what will happen?

Assuming you are using session replication, the session will be invalidated in both places. If you are planning to allow the session to move between servers, you should be using replication. (Otherwise you could get inconsistent results.)

Also, any session attribute that's not implementing java.io.Serializable will not be migrated. Does it mean I'll get null value if I call session.getAttribute("XXX") when the session is moved to server B where the attribute is set when the session is in server A? Does the behavior depend on server? (we are using JRun)

Yes, it depends on the server. WebSphere logs an exception and then places null in the session.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session behavior in distributed environment