java Android 最大线程数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35136345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 23:47:10  来源:igfitidea点击:

Maximum number of thread Android

javaandroidmultithreading

提问by Daniele

I want to know if there is a maximum number of threads that it is possible to run on an Android device. It depends on the type of the device?

我想知道是否有可能在 Android 设备上运行的最大线程数。这取决于设备的类型?

回答by Pankaj Nimgade

As commented by @Xaver Kapeller, you may create as many Threads you want but more threadnot actually the part of the solution.

正如@Xaver Kapeller 所评论的那样,您可以创建任意数量的Threads,但thread实际上更多不是解决方案的一部分。

A core(CPU) in Processorwill handle only one Task(Processor Thread) at a given time.

A core(CPU) inProcessor将在给定时间仅处理一个Task(ProcessThread) 。

so in Processorwith 1 core will handle one threadat a time. so technically no matter how many threads you open for this processorit will serve a thread at a given time. All threadswhich are running would be using processor sequentially, utilizing quantum time of processor which only seems to be concurrent.

所以在Processor1 个核心中将一次处理一个thread。所以从技术上讲,无论您为此打开多少个线程,processor它都会在给定时间为一个线程提供服务。所有threads正在运行的都将按顺序使用处理器,利用处理器的量子时间,这似乎是并发的。

Processorwith 2 core will handle 2 threadsat a time( concurrent execution of two threads).

Processor2 核将一次处理 2threads个(两个线程并发执行)。

Processorwith 4 corewill handle 4 threads at a time( concurrent execution of four threads.

Processorwith 4core将一次处理 4 个线程(四个线程的并发执行。

Processorwith 8 core will handle 8 threadsat a time( concurrent execution of eight threads. so on

Processor8核将一次处理8threads个(8个线程并发执行。依此类推

回答by vk239

Maximum number of threads possible to run on an Android device depends on whether the device has a 32-bit processor or a 64-bit processor and stack size of Android. But you will have memory constraints way before you reach the actual maximum limit.

Android 设备上可能运行的最大线程数取决于设备是 32 位处理器还是 64 位处理器以及Android 的堆栈大小。但是在达到实际最大限制之前,您将受到内存限制。

As mentioned in the article hereyou can run tests to determine maximum number of threads you can create in your Android version.

正如这里的文章中提到的,您可以运行测试来确定您可以在您的 Android 版本中创建的最大线程数。