Question about the blocking syscalls within virtual thread
Almas Abdrazak
almas337519 at gmail.com
Tue Nov 30 21:18:34 UTC 2021
Good day, thanks for giving me an opportunity to ask this question.
The question I have is about performing syscalls from a virtual thread. My
main OS is Linux so I would talk in terms of Linux. When I use InputStream
class from jdk, internally it uses read() syscall, according to man pages,
read() syscall is blocking so it will lock the OS thread until data won't
be available. So with this in mind I read JEP Virtual Threads (Preview)
According to JEP
"The implementations of these APIs are heavily synchronized and require
changes to avoid pinning when using these APIs from virtual threads."
So InputStream implementation was changed to avoid synchronized keyword,
but still it uses read() syscall right ?
Later on in the JEP there is a paragraph
"When a virtual thread tries to park, say, by performing a blocking I/O
operation, while pinned, rather than released, its underlying OS thread
will be blocked"
As far as I understand, using InputStream would still block the OS thread,
which means I can't increase the throughput of my backend if it uses JDBC
which uses InputStream under the hood(Tomcat with 200 OS threads would be
better than amount of threads equals to CPU cores all waiting on IO because
virtual threads were using InputStreams). Did I understand it correctly ?
My other assumption is that the JVM runtime detects that blocking read()
would be called and replaces it with non blocking epoll() syscall from
Linux. Please clarify this to me because I can't find any information.
Regards !
More information about the loom-dev
mailing list