问题
Is there a way to limit both the number of cores that java uses?
And in that same vein, is it possible to limit how much of that core is being used?
回答1:
You can use taskset on linux. You can also lower the priority of a process, but unless the CPU(S) are busy, a process will get as much CPU as it can use.
I have a library for dedicating thread to a core, called Java Thread Affinity, but it may have a different purpose to what you have in mind. Can you clarify why you want to do this?
回答2:
I don't think that there are built-in JVM options to do these kind of tweaks, however you can limit CPU usage by setting priority and/or CPU affinity of the JVM process. If you are on Linux take a look at CPULimit that is an awesome tool to do these kind of resource limitations.
回答3:
https://github.com/haosdent/jcgroup jcgroup is your best choice. You could use this library to limit the CPU shares, Disk I/O speed, Network bandwidth and etc.
来源:https://stackoverflow.com/questions/10487840/java-limiting-resource-usage