Java thread running on which processor? Java thread running on which processor? multithreading multithreading

Java thread running on which processor?


The JVM's thread scheduler is JVM-specific, so there is no 'universal' solution. As far as I know there is nothing available out-of-the-box, but perhaps using:

  • the Sun JVM;
  • Solaris - or Mac, as Tom Hawtin - tackline points out;
  • DTrace.

you might have some luck:

  • trace a thread-start probe, which has as args[3] the "The native/OS thread ID. This is the ID assigned by the host operating system "
  • map the native/OS thread ID to a CPU, using Solaris-specific utilities.


I've never heard of such a call, and I highly doubt there is one, as it's not really necessary, and would require extra platform-specific code.


As far as I know the standard JDK does not support it (at least up to JDK 6). If that's what you really need, you'll probably need to execute some native calls using JNI. A nice example could be found here (while it's not exactly what you need, I believe it's a good start).

There is a lot of other information you can get from the JDK, by the way, using the ThreadMXBean class (like CPU usage per thread), and maybe you can find what you're looking for there.