Here’s what I’m trying to achieve: I’m sending some packets over the cellular networks. I’m also sniffing the traffic to check a response to these packets. The response may come anywhere within the 10 hour window.
the packets that I send are all unique (to and from) and I would like to know the best way to match the packets and responses.
I can create a hashmap and put every packet sent in it real time and match it with the response when it comes back. At which point, the has map entry either stays in the hashmap or gets deleted (after being responded to).
So, now the question: What will be the best way to achieve this considering we have 2000 packets sent every minute? Will hashmap be robust enough? What about search times?
I don’t think HashMap alone will be robust enough as it is not thread-safe. I would give a try to ConcurrentHashMap.
As for larger amount of data look for some cache implementation – these usually have the ability to overflow to disk and have time expiration so you get the clean-ups for free.