I would like to limit the number of threads/processes available to the Java VM, similar to how you set the available memory. I would like to be able to specify it to just use 1 thread, or an arbitrary number.
NOTE: I cannot set it in the code, as the code that I would like to limit is a library where I cannot modify the source. So it must be a hard cap imposed on the level of the virtual machine. (Or if you could impose a thread limit on the application itself that could override libraries?)
NOTE2: The purpose of this is a performance test, to throttle a library I want to test, to see how well it would perform when it has access to a different number CPUs/Threads.
Thanks!
Each JVM server can have a maximum of 256 threads to run Java applications.
Java will benefit from multiple cores, if the OS distribute threads over the available processors. JVM itself do not do anything special to get its threads scheduled evenly across multiple cores.
One thread per processor/core will maximize processing power and minimize context switching.
Select “Processor” and click “Properties.” A dialogue box should pop up and give you the option to turn hyper-threading on or off. Some manufacturers and providers may label the option as “Logical processor” or “Enable Hyper-threading.” The process will vary by manufacturer.
The problem of CPU limits in JVM was solved in Java 10 and is backported to Java 8 from build 8u191:
-XX:ActiveProcessorCount=2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With