Hossein Hossein - 1 year ago 122
Java Question

What does Thread Affinity mean?

Somewhere I have heard about Thread Affinity and Thread Affinity Executor. But I cannot find a proper reference for it at least in java. Can someone please explain to me what is it all about?

Answer Source

There are two issues. It’s preferable that threads have an affinity to a certain CPU (core) to make the most of their CPU-local caches. This must be handled by the operating system.

In Java there is the observation that in typical programs objects are thread-affine, i.e. typically used by only one thread most of the time. So it’s the task of the JVM’s optimizer to ensure, that objects affine to one thread are placed close to each other in memory to fit into one CPU’s cache but place objects affine to different threads not too close to each other to avoid that they share a cache line as otherwise two CPUs/Cores have to synchronize them too often.

The ideal situation is that a CPU can work on some objects independently to another CPU working on other objects placed in an unrelated memory region.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download