新线程是否自动分配给Java中的其他CPU核心? [英] Are new threads automatically assigned to a different CPU Core in Java?

查看:345
本文介绍了新线程是否自动分配给Java中的其他CPU核心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,更具体地说,Android,
是自动分配给不同于我目前正在使用的CPU核心的新线程,还是我应该处理它?<​​/ p>

此外,使用Thread类创建新线程或者将Runnable提交给Executor是否重要?是否支持线程池?



这里有一个类似的问题,但答案是解释OP应如何解决他的特定问题,而不是潜入更一般的情况:
线程自动利用多个CPU内核?

解决方案


在Java中,更具体地说,Android是自动分配给不同于我目前正在使用的CPU核心的新线程,还是我应该处理它?<​​/ p >

w的决定帽子线程运行在操作系统本身处理的内核上(在Android中,基于Linux调度程序)。你自己不能影响这些决定;这些决定是自动和动态的。


使用Thread类或向Runcutor提交Runnable是否创建新线程是否重要? ,maintans是一个线程池?


关于线程运行的内核,操作系统既不知道也不关心是否<涉及code> Executor ,或者即使编写该应用程序的编程语言有一个名为 Executor 的东西。


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?

解决方案

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.

这篇关于新线程是否自动分配给Java中的其他CPU核心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆