Reputation:
When creating a thread pool with Executor
as in the code below how does one choose an appropriate value for nThreads
? Can I ask android for the number of cores that the device has and then use that information to calculate this number? What should that number be in that case?
Executor executor = Executors.newFixedThreadPool(nThreads);
Upvotes: 1
Views: 348
Reputation: 1211
Can I ask android for the number of cores that the device has and then use that information to calculate this number?
Yes. You can use Runtime.getRuntime.availableProcessors()
to do this.
Upvotes: 5