首页 > 代码库 > Java程序控制CPU使用率

Java程序控制CPU使用率

参考: http://stackoverflow.com/questions/1202184/throttling-cpu-memory-usage-of-a-thread-in-java

one way would be to adaptively sleep the threads, similarly as video playback is done in Java. If you know you want 50% core utilization, the your algorithm should sleep approximately 0.5 seconds - potentially distributed within a second (e.g. 0.25 sec computation, 0.25 sec sleep, e.t.c.).

另外,从jvisualvm里面看到的cpu使用率,是机器上面的总的cpu使用率,如果pc机是4核的话,50%的CPU,显示的是12.5%, 100%的CPU,显示的是25%。

Java程序控制CPU使用率