-
Enhancement
-
Resolution: Fixed
-
P4
-
None
-
b21
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8331624 | 22.0.2 | Johny Jose | P4 | Resolved | Fixed | b06 |
JDK-8332224 | 21.0.5-oracle | Johny Jose | P4 | Resolved | Fixed | b01 |
JDK-8333422 | 21.0.5 | Martin Doerr | P4 | Resolved | Fixed | b01 |
For virtual threads the BAOS.writeTo method is problematic as writing to the target output stream may block indefinitely and prevent a carrier thread from being released when writeTo is invoked from a virtual thread. This will be non-issue when the object monitors work is in a JDK release. In the mean-time, it may require a workaround. Replacing the synchronization with j.u.concurrent lock when a BAOS is directly used (not subclassed) is technically possible but it changes the performance in subtle ways. Instead, it may be simpler to just work around the issue with the one method with:
```
public void writeTo(OutputStream out) throws IOException {
if (Thread.currentThread().isVirtual()) {
out.write(toByteArray());
} else synchronized (this) {
out.write(buf, 0, count);
}
}
```
That is, take a (potentially costly) snapshot of the bytes and write them to the target output stream. The only compatibility concern is where something is relying on the undocumented synchronized and expects a concurrent write + writeTo be execute sequential rather than concurrently.
- backported by
-
JDK-8331624 ByteArrayOutputStream.writeTo(OutputStream) pins carrier
- Resolved
-
JDK-8332224 ByteArrayOutputStream.writeTo(OutputStream) pins carrier
- Resolved
-
JDK-8333422 ByteArrayOutputStream.writeTo(OutputStream) pins carrier
- Resolved
- links to
-
Commit openjdk/jdk21u-dev/2144c0e2
-
Commit openjdk/jdk22u/e4a1a7bd
-
Commit openjdk/jdk/819f3d6f
-
Review openjdk/jdk21u-dev/641
-
Review openjdk/jdk22u/182
-
Review openjdk/jdk/18901