In Java, or rather Android, new themes are automatically assigned to a different CPU core than the one I am currently using, or should I take care of this?
In Java, threads are just a separate execution sequence, but in Android it is a bit more complicated. Android creates one main thread for each application. This main thread is responsible for the UI and other tasks related to events (queues). To do background work, you need to create separate workflows.
Simple threads are automatically processed by the Android OS, and they may or may not work on individual cores . If you use 10 threads, it is possible that they all work on the same core, leaving all other cores inactive.
If you need to run more than one thread, and you want to run each thread on a separate kernel , you should use ThreadPoolExecutor ; it will handle the creation of threads and map them to the number of processor cores available. You can set various parameters according to your requirements. See what Android says:
ThreadPoolExecutor automatically adjusts the pool size (see getPoolSize ()) according to the restrictions set by corePoolSize (see getCorePoolSize ()) and maximumPoolSize (see getMaximumPoolSize ()). When a new task is presented in the Runnable method and is smaller than the corePoolSize threads running, a new thread is created to process the request, even if other workflows are inactive. If there is more than corePoolSize, but less than the maximum threads, PoolSize, a new thread will be launched only if the queue is full.
See ThreadPoolExecutor for more details.
It matters how a new thread is created using the Thread class or the Runnable view to the Executor, which maintans the thread pool?
yes, see answer above.
Update
Saying "use ThreadPoolExecutor to start each thread on a separate kernel", I meant that ThreadPoolExecutor can do this if it is used correctly carefully.
Java does not bind threads directly to the processor. Java leaves a thread schedule (by mapping to OS processes) in the OS, but how do we create threads that affect OS-level scheduling . However, Java may prioritize threads, but again, for the OS, these priorities must match the OS.
There are various parameters that we must consider when creating a thread pool, several of them:
i) Threads should be the same in complexity.
ii) Comparison of CPU-bound tasks with I / O binding, I / O-bound tasks typically require more threads than the available kernel for optimal CPU utilization
iii) The relationship between flow effects is negative
If threads are created based on these points, a ThreadPoolExecutor can help achieve 100% CPU utilization, which means one thread per core (if the thread pool size is equal to the number of cores, and no other thread is running). The advantage of ThreadPoolExecutor is that it is cost-effective compared to creating threads separately, and also eliminates context switching, which takes many processor cycles.
Achieving 100% CPU utilization while performing operations is no easy task.