D
D
Dmitry Osipov2019-01-18 12:29:32
Java
Dmitry Osipov, 2019-01-18 12:29:32

How does a java thread select a processor core?

Good day to all.
Let's say we create a pool of sweats and run it to count a complex task.

ExecutorService service = Executors.newFixedThreadPool(12);

    for (int i = 0; i < 500; i++) {
      service.submit(() -> new DustCounter().countAllDustInRoom());
    }

The question is - is each thread bound to a specific core, or can it be executed on a different core during the execution of the program?
I assume that when a thread is created, it is bound to some kind of core, since all objects (not volatile) created by this thread appear in the L1 cache of the processor. As I understand it, the cores have access only to their L1 cache, and if the thread is executed on another core, it will not see its objects that are in the cache of another core
. Do I think correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pfg21, 2019-01-18
@Shiftuia

Neither Java nor your program distributes process threads in any way.
it is a separate OS kernel service - Operating System Manager .
how the choice of processor for execution is implemented, see the technical documentation for the OS.
Usually, threads are not tied to processors, which is free and they shove them there.

R
rPman, 2019-01-18
@rPman

Keywords - google: java cpu affinity
Different operating systems have their own tools. I know for sure there are java wrappers to manage this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question