On Wed, 24 Apr 2024 14:52:45 GMT, Brian Burkhalter <b...@openjdk.org> wrote:
>> Using a subclass to count the number of invocations of toByteArray seems a >> bit strange but in general it is more robust to not rely on a method that >> may be overridden by a subclass. So I think the suggestion is good. > > Currently we have > > public void writeTo(OutputStream out) throws IOException { > if (Thread.currentThread().isVirtual()) { > out.write(toByteArray()); > } else synchronized (this) { > out.write(buf, 0, count); > } > } > > where `toByteArray()` is `synchronized`, but here I would think that we'd > want to replace it with simply `Arrays.copyOf(buf, count)` without the > `synchronized`, no? @bplb My interpretation was that we didn't want to hold the monitor *during* out.write(). ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/18901#discussion_r1578034781