I had a problem a while ago whilst using Solaris that I wanted to limit the number of CPUs that Java could see (that was returned by Runtime.getRuntime().availableProcessors(). I thought I had it and I was given some info for Linux and took it on faith. I was told that using taskset would limit the number of CPUs that java would use (which is true, it does) but it does not change what is returned by availableProcessors().
I've searched quite a bit to find some way of changing this availableProcessors() return value and I haven't managed to find anything. Does anyone know a way to limit it or why taskset -c 0,1 java -cp ./ Test would not work.
Test.java
public class Test {
public static void main(String args[]) {
System.out.println(Runtime.getRuntime().availableProcessors());
}
}
Cheers