Throttling CPU/Memory usage of a Thread in Java?

前端 未结 9 2285
借酒劲吻你
借酒劲吻你 2020-12-07 13:00

I\'m writing an application that will have multiple threads running, and want to throttle the CPU/memory usage of those threads.

There is a similar question for C++,

9条回答
  •  渐次进展
    2020-12-07 13:31

    You can get a lot of info about CPU and memory usage via JMX, but I don't think it allows any active manipulation.

    For controlling CPU usage to some degree, you can use Thread.setPriority().

    As for memory, there is no such thing as per-thread memory. The very concept of Java threads means shared memory. The only way to control memory usage is via the command line options like -Xmx, but there's no way to manipulate the settings at runtime.

提交回复
热议问题