First of all, I apologize that this doesn't directly have anything to do with
servlets, other than that that's where this code is to be used. If there's a
better forum for general java questions like this, please point me to it.
I'm in a situation where I have a UserSession class that's going to represent a
user session for all applications served by my company. To allow developers
using this package the flexibility of doing String-->String key-value mappings
I'm using a hashtable inside of this class. However, I have a problem in that
the user may use a variable number of applications, and I need to maintain a
clean namespace across all key-value pairs.
To accomplish this, all get/set methods for session data will include an
AppPrefix. What's the most efficient way to code this, keeping in mind the
fact that a user will probably use < 5 applications in a session?
I see the options as follows:
1) Use 1 hashtable in the UserSession class and prefix the AppPrefix to all
keys for get/set methods. i.e. code the method as follows
UserSession.getValue(String sAppPrefix, String sKey) {
return (String) this.myHash.get(sAppPrefix + sKey);
}
This has got to be the fastest way to do this, but it feels like a hack.
2 (BAD) Use a vector of hashtables, with a distinct hashtable for each
application and iterate through the vector for every access.
3 (WORSE) Or, use a global hashtable with the sAppPrefix as a key pointing to
another hash table for each application.
IMHO, it seems like 1 would be fastest in almost all cases. Are there any
situations where you'd want to use solutions 2 or 3? Am I correct in
understanding that 2 and 3 would melt down in a heavy-load heavy-data scenario
because all Vector and Hashtable methods are synchronized? Are there any
situations where you'd want to use either of them?
Thanks for the input,
-Tim
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html