Thursday, January 3, 2002 09:03 PM
This tricky stuff here is that you will have multiple threads running at the same time and the servlets will be multi-threaded to support multiple users at once. This would happen if used servlets or if you wrote your own Java server/listener app.
Try using a singleton pattern where you have a static class that creates a single HashMap. Make sure the accesses are synchronized and then have the servlet call this singleton class to update and read the keys in the HashMap. That should allow all threads to see the common data, and sychronizing the accesses should avoid corrupting the HashMap.
If you need to keep the keys longer, or have many JVMs, you could make the servlet write the keys to a file and "sychronize" of a semaphore-file.
I can write some quick code frags if you need me to clarify this point.