On Sat, 9 Oct 2021 18:10:34 GMT, liach <d...@openjdk.java.net> wrote:
> > in extream situation, when doing this.skipBuffer = skipBuffer in Thread B, > > it might make this.skipBuffer to a byte[6] in thread A, and thus cause a > > IndexOutofBoundException in Thread A. > > No, it won't. The later `skipBuffer` references are made to the local > variable; so even though the `new byte[6]` may replace the cached `new > byte[10]` skip buffer in instance field, in thread A, it is still using the > old `new byte[10]` which is stored in the local variable/stack, and > everything just proceeds fine (only shortcoming is that the 10-length skip > buffer is wasted and recycled) you are correct. I forgot you use same name local variable hiding the field variable, so the later skipBuffer passed to read() is local variable. (sigh) I feel like super stupid when facing multithread programming. ------------- PR: https://git.openjdk.java.net/jdk/pull/5872