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 Do sessions use hashing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Do sessions use hashing?" Watch "Do sessions use hashing?" New topic
Author

Do sessions use hashing?

Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
Do sessions use hashing to organize their data?
I assume this is container-specific. I wonder if I would get a perf boost from adding hashCode method to objects that I'm putting in my sessions for Tomcat.


comp.lang.javascript FAQ: http://jibbering.com/faq/
Mark Bensing
Ranch Hand

Joined: Mar 09, 2003
Posts: 40
I dont have knowledge of how session attribues are implemented for any particular container, but consider that the session attribute key is always a String. So if a Hashtable/HashMap is being used to store the attributes (as I would guess is probably the case), it is the hashCode() and equals() method of the String key that would be used, not any such methods that are defined in your class.
Mark
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
In Tomcat and presumably other servlet engines, a session object is tracked using the sessionID (a String) as a key in a Hashtable or similar collection. Inside the session named objects are stored in a Hashtable keyed by the name (a String). This is already very efficient.
Of all the many things affecting performance in Servlets, the session mechanism is probably the least important.
The number one place to look for time wasting (IMHO) is anywhere you build up Strings and print them to the response.
(Unless you are doing JDBC queries in which case look there for time wasting).
Bill
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
Yeah, sessions use Strings for keys. What was I thinking?
Christopher Dixon
Greenhorn

Joined: Jan 30, 2002
Posts: 22
Of all the many things affecting performance in Servlets, the session mechanism is probably the least important.

I think the specifics of the in-memory mechanism itself aren't very important, but being aware of the volume/frequency of session updates by the application is critical for scalability.
It is especially important for a cluster, where agressive session persistance settings in the container config may cause modifcations to the session to persist directly to a datasource.
These concerns are probably more architectural than impementation, but everyone along the way should be aware.
JMHO,
Chris
[ April 06, 2003: Message edited by: Christopher Dixon ]
[ April 06, 2003: Message edited by: Christopher Dixon ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
Good point Christopher.
Incidently, if you are interested in performance traps in server applications, Bitter Java by Bruce Tate makes a great read. Sort of an anti-patterns collection for web applications.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do sessions use hashing?
 
Similar Threads
use of hashing as an authenticated mechanism
InvalidKeyException in 3DES
password hashingsalting in struts
Problem on String
Hash Tables