Because memory allocation can be relatively slow and can be done when the array is unlocked.
By releasing the lock, it allows other threads to continue working while it allocates a (potentially large) new array.
How this process can be done without blocking is a good practice. You should only hold the lock for a minimum period of time.
Sufficient checks are performed to ensure that no other thread will do this at the same time.
UNSAFE.compareAndSwapInt(this, allocationSpinLockOffset, 0, 1)
will only allow one thread to this section of code at a time.
pay attention to
lock.lock();
if (newArray != null && queue == array) {
, , , , , . , , , , - .
, .
Kamil .
- , , "".