当使用 Executor
创建线程池时,如下面的代码所示,如何为 nThreads
选择合适的值?我可以向 android 询问设备拥有的核心数量,然后使用该信息来计算这个数字吗?在这种情况下,该数字应该是多少?
Executor executor = Executors.newFixedThreadPool(nThreads);
最佳答案
Can I ask android for the number of cores that the device has and then use that information to calculate this number?
是的。您可以使用 Runtime.getRuntime.availableProcessors()
来执行此操作。
关于java - 我如何为执行程序选择线程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53089062/