2

I know I can use a fixedThreadPool to limit the amount of threads my program uses at one time. If I use a cachedThreadPool and could run 10,000 threads, will the JVM schedule them appropriately so not too many are running at the same time?

Nick
  • 1,743
  • 6
  • 23
  • 38
  • The JVM won't schedule them at all. The operating system does that. The number that can really be executing at the same time (as opposed to runnable) is bounded by the number of CPUs and cores you have, not byte JVM. – user207421 Jun 11 '15 at 22:47
  • you might want to re-think your application design if you need that many threads. If it's for network IO consider using nonblocking sockets. if it's file IO either use `AsynchronousFileChannel` or just queue IO requests on a limited amount of threads, spinning up more threads won't make spinning rust seek faster. – the8472 Jun 12 '15 at 08:19

1 Answers1

3

JVM is tied to OS limitations. OS is tied to Virtual memory, swap space and stack size limitations.

Three stackoverflow threads below should explain:

Community
  • 1
  • 1
Chaitanya P
  • 120
  • 7