Concurrent add on non threadsafe HashSet - what is the worst that could happen?

后端 未结 3 2079
庸人自扰
庸人自扰 2020-12-20 00:33

Situation:

Multiple Threads are only adding values to a non threadsafe java.util.HashSet and no other operation is done on the Se

3条回答
  •  误落风尘
    2020-12-20 01:03

    The worst that can happen (besides an erroneous state of course) is probably an infinite loop when adding a value, blocking one of your threads.

    See Paul Tyma article for more information on this case.

提交回复
热议问题