Java – Setting java to use one cpu

cpu-usagejavasolaris

I have an application that has a license for a set number of cpus and I want to be able to set the number of cpus that java runs in to 1 before the check is done. I am running Solaris and have looked at pbind but thought that if I started the application and then used pbind it would have checked the license before it had set the number of CPUs that java could use.

Does anyone know a way of starting an application with a set number of CPUs on Solaris?

Best Solution

It is a workaround, but using Solaris 10 you could set up a zone with a single CPU available and then run the application inside that zone.

If you want to do testing without running the full application, this bit of Java is most likely what they are using to get the number of CPU's:

Runtime runtime = Runtime.getRuntime();
int nrOfProcessors = runtime.availableProcessors();

A full example here.