as title is descriptive i want to restrict CPU usage of a java application that runs in windows to specific amount (namely 2 GH)
this app could be a ".jar" file or an app which runs by IntelliJ IDEA or Eclipse
as title is descriptive i want to restrict CPU usage of a java application that runs in windows to specific amount (namely 2 GH)
this app could be a ".jar" file or an app which runs by IntelliJ IDEA or Eclipse
Limiting resources like CPU is an operating system related question.
No parameter in java can be used to limit per percentage of CPU used.
Additionally you don't limit the frequency of your CPU, but only the percentage of use. So if you have a 3Ghz CPU you can limit it at 66%. It means that no more than 66% of time the CPU will be used by java, but for this 66% it can be used at 100% of its speed.
The only way to limit a JVM without use an OS in a VM with limit CPUs, is to have the application limit itself. When it is using more CPU than you would like you have to make it sleep the threads it is running. There is no way to do this autogamically, instead you have to add this to you code, possibly in every place it could use a lot of CPU.