0

I have a application that I hard coded to use 4 threads/player.

However, (on a dedicated system) more threads would be more efficient depending on how many players are playing at the same time. (I would theoretically could go up to 30/player.)

Is there a way to measure the maximum number of threads I could use at startup of the calculation?

I guess by having a big calculation and add threads until they start interrupting each other, but I wouldn't know how to check this...

SanThee
  • 2,301
  • 3
  • 23
  • 35

2 Answers2

1

there are so many factors which would ultimately factor in to whether or not a given system could support a certain number of threads. that said, i would try to correlate how your app performs for X number of threads per cpu in the system. Once you have determined a reasonable value for X, you can get the system cpu count for the current system and multiply by X to determine the number of threads to use.

jtahlborn
  • 52,909
  • 5
  • 76
  • 118
0

This is a good starting point Runtime.getRuntime().availableProcessors()

See also here for further discussion: Finding Number of Cores in Java

David Soroko
  • 8,521
  • 2
  • 39
  • 51