Java limiting resource usage

前端 未结 3 790
借酒劲吻你
借酒劲吻你 2021-02-19 04:48

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?

相关标签:
3条回答
  • 2021-02-19 05:32

    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?

    0 讨论(0)
  • 2021-02-19 05:41

    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.

    0 讨论(0)
  • 2021-02-19 05:46

    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.

    0 讨论(0)
提交回复
热议问题