aspose file tools*
The moose likes I/O and Streams and the fly likes ObjectOutputStream thread issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "ObjectOutputStream thread issue" Watch "ObjectOutputStream thread issue" New topic
Author

ObjectOutputStream thread issue

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Hey all,

I am writing a small chat server for one of my classes. I am using a multi-threaded client/server model so whenever a client connects a new thread is created to hold the client/server interactions, I am passing data across sockets using ObjectOutputStreams and ObjectInputStreams. I am running into an issue where some of my methods only work for the LAST client that connects, which leads me to believe that I am overwriting data somewhere I just cant seem to find where. I was hoping someone could spot my mistake.

ThreadHandler:


Client:


Sorry for the long post, any ideas would be great!

Thanks.
Hunter.


"If the facts don't fit the theory, get new facts" --Albert Einstein
Andrey Kozhanov
Ranch Hand

Joined: Mar 12, 2010
Posts: 79
Hello!

You didn't provide the full code therefore it's hard to say where the problem is. Also you didn't tell what particular methods does not work as expected. So I can only guess that this might be methods, which calls ChatServer.getClients() and similiar functions, i.e. static functions that return collections. The matter is that returning static Collection instance 'as is' might not work properly. To fix this problem the function should return Collection.clone().
 
wood burning stoves
 
subject: ObjectOutputStream thread issue