Reputation: 3614
In a parallel Java code can we learn which core a thread is executed on?
Say that I have 10 threads and 4 cores, is it possible to learn which core is used for thread 1, thread 2, thread 3 etc in code?
It is not a crucial problem but I wonder if it is possible.
Upvotes: 1
Views: 116
Reputation: 116858
In a parallel Java code can we learn which core a thread is executed on?
From inside of Java, the answer is no. There are ways to look at the process list in Linux (and maybe other Unixen) that could show you the virtual processes and maybe CPU affinity. This is very non-portable however and for tasks that are context switching, it is not going to be meaningful.
I have some more details about CPU info here but it doesn't address the affinity question: Concurrency of posix threads in multiprocessor machine
Upvotes: 2