RFR: 8349543: LinkedBlockingDeque does not immediately throw InterrruptedException in put/take
Alan Bateman
alanb at openjdk.org
Mon Feb 10 08:42:11 UTC 2025
On Wed, 5 Feb 2025 15:36:15 GMT, kabutz <duke at openjdk.org> wrote:
> The LinkedBlockingDeque does not behave consistently with other concurrency components. If we call putFirst(), putLast(), takeFirst(), or takeLast() with a thread that is interrupted, it does not immediately throw an InterruptedException, the way that ArrayBlockingQueue and LInkedBlockingQueue does, because instead of lockInterruptibly(), we call lock(). It will only throw an InterruptedException if the queue is full (on put) or empty (on take). Since interruptions are frequently used as a shutdown mechanism, this might prevent code from ever shutting down.
I think this is okay. Anything calling these methods already has to deal with InterruptedException. I see that the implementation offerFirst/offerLast/pollFirst/pollLast is using lockInterruptibly so if usage extends to these methods then there is already the possibility of the exception when calling them with the interrupt status set.
Given the behavior change then a CSR + release notes would be good but I think it's overall.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23464#issuecomment-2647283704
More information about the core-libs-dev
mailing list