With unlimited connections, you can potentially create a huge number of threads. This means that a lot of processing is required, and each thread will consume a fixed amount of memory by default only for the heap (I think the figure is 512 kB per thread, but it depends on the platform).
By combining a fixed number of threads and accepting a limited number of clients, you guarantee that some of your clients will be served for a reasonable period of time, and your server will not crash during congestion.
You can check out this article about building servers using NIO, or maybe check out frameworks like Apache Mina .
source
share