3 ms·
Thousands of threads is not a problem for any modern OS if you have enough RAM. Loom takes it up into the millions. As for why the JVM can do this and you can'
by native_samples 4y ago
Thousands of threads is not a problem for any modern OS if you have enough RAM. Loom takes it up into the millions.
As for why the JVM can do this and you can't with other runtimes, it's because it needs a complex runtime with very tight integration between the compiler, the GC, the threading library and various other subsystems. That's why the moment you make a native call the JVM loses the ability to switch between the virtual threads and has to start up more OS threads to compensate - it didn't create the code that's running on the stack at that point, so it can't work its usual magic.
Fortunately the whole 'pure Java' movement of some decades ago means that actually you can do a heck of a lot of stuff without using native code. It's an ecosystem way less dependent on C extensions than most other languages.