In Java, is there a way to force a JVM instance to run on a single CPU/Core.
Additionally is there a way for giv开发者_开发技巧en thread to figure out what CPU it is running on?
This is not to be controlled at JVM/Java level, but at OS/platform level. In Windows for example, you can go to the Processes tab in the Task Manager and set the Affinity for most of the processes by choosing the appropriate option in the rightclick menu. With this you basically controls which CPU's/cores the process is allowed to use.
Is there a way to force the JVM to run on a single processor or Core.
Yes. There are OS-specific tools for doing this.
In Java, is there a way to force a JVM instance to run on a single CPU/Core.
No.
Additionally is there a way for given thread to figure out what CPU it is running on?
No. (A thread figuring this out implies that you are doing this in Java ...)
Those answers should be qualified by saying that is is not possible to do these things in pure Java. You might be able to use JNI to call some OS specific native APIs to do these things. But it is simpler and cleaner to do the task from the command prompt or from some appropriate OS management GUI.
精彩评论