I am creating a web-based application that would be used as a messaging system. Sort of like Yahoo Messenger or Windows Messenger except that it is customized according to the client's requests.
Each user has a console to send/receive/view messages. All the messages received and send by each user would not be directly stored in the DB. Every message received/send would be 1st stored in a sort of message queue memory and after a certain amount of time, would then be purged and stored in the DB. The "memory" used is a singleton class which stores all of the message objects in Lists inside Hashmaps with their keys depending on their classification. The messenger console refreshes every X seconds and retrieves the messages for each user and retrieves this from the singleton which acts as the memory. In retrieving the messages, I decided not to hit from the DB since that would cause performance issues in connecting to the DB even if there is connection pooling. Remember that the page refreshes every X seconds to receive incoming messages in real time and there are approximately 50 users that will be using this.
Now, the problem is...once there are already a number of messages stored in the memory. The console page starts to freeze and after some time, the entire system throws an OutOfMemory exception. Is this caused by the memory class? Can anyone enlighten this novice developer what to do?
If this was my problem I would start by monitoring memory usage with the various methods in java.lang.Runtime. Perhaps you could log the totalMemory and freeMemory values to see if memory available drops slowly or suddenly. Are you using the default memory allocation or setting a higher one? (see the tooldocs for the command line memory related parameters) How many Threads are in operation here? It looks like an opportunity for a separate low priority Thread to do the DB backups while one or more high prioriy Threads handle communication. Bill
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps