Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are new threads automatically assigned to a different CPU Core in Java?

In Java, and more specifically, Android, are new Threads automatically assigned to a different CPU core than the one I am currently utilizing, or should I take care of that?

Also, does it matter how the new thread is created, using the Thread class or submitting a Runnable to an Executor, that maintans a pool of threads?

There is a similar question here, but the answer goes on to explain how the OP should address his particular problem, rather than diving into the more general case: Threads automatically utilizing multiple CPU cores?

like image 393
Kaloyan Roussev Avatar asked Nov 09 '15 22:11

Kaloyan Roussev


1 Answers

In Java, and more specifically, Android, are new Threads automatically assigned to a different CPU core than the one I am currently utilizing, or should I take care of that?

The decision of what threads run on what cores is handled by the OS itself (in Android, based off of the Linux scheduler). You cannot affect those decisions yourself; the decisions are automatic and dynamic.

does it matter how the new thread is created, using the Thread class or submitting a Runnable to an Executor, that maintans a pool of threads?

With respect to what cores a thread runs on, the OS neither knows nor cares whether an Executor is involved, or even if the programming language that app was written in has something called Executor.

like image 99
CommonsWare Avatar answered Oct 20 '22 01:10

CommonsWare