Java limiting resource usage

2019-04-04 03:19发布

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条回答
Root(大扎)
2楼-- · 2019-04-04 03:42

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楼-- · 2019-04-04 03:44

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.

查看更多
女痞
4楼-- · 2019-04-04 03:52

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?

查看更多
登录 后发表回答