Suppose I have a hash set of request IDs that I've sent from a client to a server. The server's response returns the request ID that I sent, which I can then remove from the hash set. This will be run in a multithreaded fashion, so multiple threads can be adding to and removing IDs from the hash set. However, since the IDs generated are unique (from a thread safe source, let's say an AtomicInteger
for now that gets updated for each new request), does the HashSet
need to be a ConcurrentHashSet
?
I would think the only case this might cause a problem would be if the HashSet
encounters collisions which may require datastructure changes to the underlying HashSet
object, but it doesn't seem like this would occur in this use case.