If you have 4 cores, the optimal thread pool size can be 4, as this is the minimum number of threads needed to keep all processors busy. However, you can have any number of idle / waiting threads up to 10K. This is the polling point of the JVM thread library, so switching to Scala will not make any difference. Note: you can have many more threads, I would not recommend it.
If you have 10K streams and want more, I suggest you buy another server. You can buy a lot for the server for about $ 1,000.
I tested the test by creating many threads on my machine, upgrading to Java 6 26, 32-bit and 64-bit on Ubuntu 11. The first 1000 threads took 72 ms to create, starting from 31K to 32K, they took 3,861 ms to create. With approximately 32K threads, I got this error
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:640)
source share