• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get the size of the Session !

 
Vibhor Mittal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on some JSP/Servlets application. It has a Shooping cart kind of thing, which I am keeping in my session. Every item added in the cart has different information and thus I need to get the current size of the Session before every new adition. I don't want it to become too heavy. I want the user to check out the items, if the session size exceeds a particular size. Though I can do this by keeping track of number of objects of different types in the session, but I don't want to do it that way. could any one suggest any other way of doing this.
 
Dhananjay Inamdar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I don't think that there is direct method to check the SIZE of the SESSION object.
There is one method of the SESSION object is "getAllAttributes", which returns the enumeration containing all the attributes stored in session. After receiving this enumeration you can check the size of this enumeration, which in turn will be the size of SESSION.
I hope this will solve your problem
-Dhananjay
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The size of the enumeration will give the number of references, not the total memory used. There is no direct way in Java to get the exact memory used for something like a session. You can get a rough idea by serializing it out to a file and looking at the size of the file.
Bill
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:
... There is no direct way in Java to get the exact memory used for something like a session. You can get a rough idea by serializing it out to a file and looking at the size of the file.
Bill

That only works if 1) your session objects all implement Serializable and 2) The size of the .ser file is probably actually larger than the actual memory used by the session, because serialization includes class names and static class information.
Actually, I think the remote debugging API *does* provide a way to measure memory usage. It's possible to use this with IBM WebSphere, which has a Performance Monitor tool. I am not really sure about exactly how it works though. Maybe someone can clarify.
 
Sudd Ghosh
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael -
What is this "remote debugging API" ? Is this in the Java API specs or is it WebSphere specific ?
Thanks, Sudd
 
Vibhor Mittal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Zalewski:

Actually, I think the remote debugging API *does* provide a way to measure memory usage. It's possible to use this with IBM WebSphere, which has a Performance Monitor tool. I am not really sure about exactly how it works though. Maybe someone can clarify.

Do u know something of the same flavour in Weblogic.
:roll: :roll: :roll:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!