File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Where are data in HTTPSession stored? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Where are data in HTTPSession stored?" Watch "Where are data in HTTPSession stored?" New topic
Author

Where are data in HTTPSession stored?

Cainiao Zou
Ranch Hand

Joined: Mar 03, 2009
Posts: 36
HTTPSession is a high level interface built on top of cookie and url-rewriting, that means there is only a session id stored in client, the relative big data are stored in server.
I'm not talking about how to save data with HTTPSession interface. I'm just wondering where are the data actually stored in server? In the memory or somewhere?
How can I change the place to store, e.g. I want to save them into a in-memory database, how could I do that?
Btw, if it's not in a database, is there any concurrency problem when many client work on a same session data at the same time?

thanks
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Yes, it's stored in memory. Some servlet containers write sessions to disk during a restart, but not during normal operation.

Why would you as the application developer care about where the sessions are stored, or want to interfere with a mechanism that is working fine?

Indeed, the content of sessions is not thread-safe unless you take precautions to make it so. That's generally not a big deal, because sessions are normally restricted to single users. So the "many client" scenarios you describe should not happen.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
It is my understanding that Servlet containers are allowed to write sessions to disk any time they want to - presumably this would come up when free memory is getting low. This is why your objects having references in a session need to be Serializable.

Bill
Sunil Sunny
Ranch Hand

Joined: Oct 18, 2011
Posts: 41
is there any concurrency problem when many client work on a same session data at the same time?

For every client a new session is created . you do not have worry about that and i think there is no way a client can interact with another client's session . (may be possible if you know the session id). Why are yu trying to change the storage space for session data?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Can you elaborate about this "many clients, same session" scenario? As I said, each client gets their own session. Sessions are not appropriate for storing data for many clients.
Sunil Sunny
Ranch Hand

Joined: Oct 18, 2011
Posts: 41
Tim Moores wrote:Can you elaborate about this "many clients, same session" scenario? As I said, each client gets their own session. Sessions are not appropriate for storing data for many clients.


This is true "each client gets their own session." i know that . Who said many clients and same session?. The misunderstanding has occured because I just copied the first line from the topic starter's post.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Who said many clients and same session?

You did, by asking about it. If that was a quote you should make that obvious by using quote tags. Otherwise it looks like regular content.
Sunil Sunny
Ranch Hand

Joined: Oct 18, 2011
Posts: 41
Ok actually i was in a hurry at that time . I will care for it the next time .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where are data in HTTPSession stored?