jjenkov / java-resizable-array

A resizable array implemented in Java.
Apache License 2.0
39 stars 27 forks source link

can not be used in concurrent situation #5

Open carl-don-it opened 3 years ago

carl-don-it commented 3 years ago

the buffer should use some lock or cas to support concurrency

jjenkov commented 3 years ago

Hi - If the buffer introduces a lock of some kind - it will be hurtful to all uses in single-threaded designs - as these will get an uncessary lock overhead.

As a solution I suggest wrapping the non-concurrent buffer inside a concurrent buffer, and guard reads and writes to the buffer with lock calls.