I have the below scenario:
- A huge list of messages from external system (Message contains a id and a payload)
- I am filtering those messages based on the id and storing the payload in a list and finally the id and List in a map.
- Later on based on the id I am retrieving the list of payload from map and submitting the entire list of payload for further processing to an executor service.
Well, I do not like this approach as at run time I am having a map containing all data (Point 2). I might end up with memory related issue. Is there any good alternative of the above approach.
EDIT
I am using Java. I am getting the messages from some external system (I have no idea about the volume of messages that could come) and finally processing them based on their ID. After processing these are getting stored in the database. However, the problem is while I am loading the messages into Map based on the ID. I have to group the messages based on the ID and then send for processing. So I have to keep the entire Map in memory for certain period of time.
Thanks in advance.