Java Chat Multi-Client Receiving thread

Tags: , , ,



In a lot of multclient java programs people use a separate thread which only receives the messages from the server. Is it really necessary? Why can’t it be done in the main thread? What should be the problem?

For me a separate thread to receive the messages from the server is not that necessary, it could be done simply be the main.

Am I wrong?

Answer

After 6 years I would like to answer myself of the past.

Some more context: the multi-client chat is a GUI chat that used swing. It was a high school project.

The main method would go in a loop to read messages received from a server. Since every other client action is event-based, the event handling would be done on a separate thread anyway.

So yeah, it worked fabulously at the time!



Source: stackoverflow