I have a huge HashMap that is allocated per application user. I have three options to store this HashMap
#1. Store the map in the user session (such as HttpSession)
#2. Bind the map to a JNDI context such that i.e., context.bind(userid, new HashMap());
#3. Have a database table with userid & BLOB columns with the blob column being the serialized HashMap.
Approach #1
-----------
Although the fastest is also the fastest way to get to an OutOfMemoryError, as I am allocating new objects per user. For 1000 concurrent users, I could quickly be running out of heap
space. Worst yet in a browser based application, the HttpSession is invalidated only at intervals of say (minutes) and canceling the browser would hold those objects for atleast that many more minutes before I can null them and *qualify* them for garbage collection.
Approach #2.
-----------
I am basing this on the assumption that JNDI binds objects to
the disk and not the memory. (I really need clarification on this one). This would be slow as I would have to lookup the HashMap but then once I have a handle to the HashMap I can do O(1) gets on the map (I guess?). Binding objects to the JNDI, I HOPE is not taking up
java heap. (Please clarify)
Approach #3.
-----------
The slowest and also the most memory efficient (I guess) approach. I will be getting objects directly from the DB.
My priorities for this are as follows:
1. Scalability: I want to be able to support an ever increasing
number of users without choking the JVM.
2. Speed.
Note: Speed is not the first one :-)