[MUD-Dev] Java I/O and threads.

Elis Pomales pomales at caip.rutgers.edu
Mon Jan 25 10:19:02 New Zealand Daylight Time 1999

Hi there!

I decided its about time I posted something useful! Well I hope!

I have been writing a MUD server for the last few months. I have been
writing it in Java. I first started with a Interpretor and my own
language. But Java was way too slow (or I just could not get reasonable
speed) So I threw that project out and started working on a pure Java
server. The server is coming along nicely, but I have run into an issue.

The current dilemma, is whether I should use threads on a per player (per
socket) basis, or implement a polling loop and queue player commands,
handling one command per player per loop cycle. The problem with having a
thread per player is the context switching overhead. The problem with the
polling loop is that I have to check each player to see if they have
input. (There is no select() in Java.) Furthermore, processing one command
per player may make the system very unresponsive??? Making it seem turn

What solutions have you guys (and gals?) employed in your servers? 
I guess one way to use the polling loop would be to keep each command as
small as possible...

PS. I would still use more threads, one for NPC's and one for the game

PSS. Is having 100+ threads really that bad? (I would think so)

Elis Pomales
pomales at dreamscape.com

More information about the MUD-Dev mailing list