Java socketserver: How to handle many incoming connections?

Posted by SlappyTheFish on Stack Overflow See other posts from Stack Overflow or by SlappyTheFish
Published on 2010-03-17T22:05:45Z Indexed on 2010/03/17 22:11 UTC
Read the original article Hit count: 315

I am writing a simple multithreaded socketserver and I am wondering how best to handle incoming connections:

  1. create a new thread for each new connection. The number of concurrent threads would be limited and waiting connections limited by specifying a backlog

  2. add all incoming connections into a queue and have a pool of worker threads that process the queue

I am inclined to go for option 2 because I really don't want to refuse any connections, even under high loads, but I am wondering if there are any considerations I should be aware of with accepting effectively unlimited connections?

© Stack Overflow or respective owner

Related posts about java

Related posts about socket