user10564330
user10564330

Reputation:

how do I choose number of threads for Executor

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

Answers (1)

a3y3
a3y3

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

Related Questions