Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is a reasonable number of threads for a simple 2D mmo in Java? Is it reasonable to have two threads per connection, one for the input stream and one for the output stream?

The reason I ask is because I use a blocking method on the input stream, and a workaround seems unnecessarily complex if I were to try to get around it without adding threads.

This is mostly for my own edification; I don't expect to have 5 million people playing it ever, or even 5, but I'm wondering what a good scalable solution is, and if this is reasonable for a small server (<30 connections).

share|improve this question
Possible duplicate:… – Byte56 Nov 11 '13 at 3:06
Could you have one central thread for output? (I have no idea about MMO design) Or even a thread pool of output workers? – ThorinII Nov 11 '13 at 5:35
@Byte56: That link seems to be about client threading, whereas this question seems to be about scalability of threads on server. Regarding number of threads in Java, search for Non-blocking I/O (NIO) versus Blocking I/O. E.g.… – msell Nov 11 '13 at 5:39
up vote 1 down vote accepted

I think the better solution is to not reinvent the wheel here. Many Java libraries have been created to handle java networking & scalability, for example Netty or KryoNet. Another thing you either failed to consider or list was what kind of server architecture are you building out? Is this distributed, centralized, what? There is different approaches for different architectures, but these libraries are a good starting point.

Sorry if this doesn't answer "how many threads should I use", but these libraries will take care of all of this for you and it's really the better approach.

share|improve this answer

To quote coding horror: "Everything is fast for small N". Your N is small enough to make it really not matter just about anything should work. Your approach isn't memory efficient so it isn't going to scale to thousands of users.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.