In my application I would be using a Map.
I would like to know the following :
Focusing on these points:
The data that is fed to the map has a different key during every write
The data in the map would not be read at any point in the application
You don't need a Map
at all. I'm assuming that when you state that the data in the map won't be read, you mean that you're not doing map.get(someKey)
but instead you will traverse the whole map to store the data in the file (or whatever data source you use).
This point:
- Once in a while the content would be dumped to a file
Reinforces the recommendation above.
Focusing on this point:
- Multiple threads would be writing data to this map.The write operations are too many.
The best recommendation is to use a BlockingQueue
. As implementation, you may use LinkedBlockingQueue
.
In case you dump the data from the Map
using Java synchronization and want/need to recover this data in form of a Map
, then use a ConcurrentHashMap
. If this is not part of your use case because you will read the data from the file on other ways, then avoid using Map
and use BlockingQueue
.