java多线程 cpu分配,新线程是否自动分配给Java中的其他CPU核心?

本文探讨了Java中Android新线程是否自动分配到不同CPU核心的问题,指出线程调度由操作系统决定,程序员无法干预。同时,创建线程的方式(Thread类还是Executor)不影响核心使用,重点在于理解操作系统的资源调度原理。
摘要由CSDN通过智能技术生成

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值