Does Java thread run on which processor?

Is there a way to find out which processor (both on the same system and on multiple systems) is running on your thread using native Java threads? If not, is there a library that could help?

+7
java multithreading processor
source share
5 answers

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

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

you might be lucky:

  • trace a thread-start probe that has args[3] "Native / OS thread identifier. This is the identifier assigned by the host operating system"
  • map the native / OS thread ID to the processor using utilities specific to Solaris.
+2
source share

I have never heard of such a call, and I doubt very much that it is, since it is not needed, and will require additional code for a specific platform.

0
source share

As far as I know, the standard JDK does not support it (at least until JDK 6). If you really need it, you will probably have to make some of your own calls using JNI. A good example can be found here (although this is not exactly what you need, I consider this a good start).

There is a lot of other information that you can get from the JDK, by the way, using the ThreadMXBean class (for example, using a processor for a thread), and maybe you can find what you are looking for there .

0
source share

The OS will schedule threads on different processors at different times. Therefore, even if you get a snapshot where each thread is running at any time, it may be out of date for milliseconds.

What is the problem you are trying to solve? Perhaps you can do what you want without knowing it.

0
source share

Invalid abstraction layer.

Your program should take care to divide the work that it should do into threads and send them to the JVM for planning. How it works (the JVM or the underlying operating system or whatever), and which processor / kernel ends with your thread, should not be a factor in developing a program, at least for a program written for / in an environment like Java.

-one
source share

All Articles