This may be because you are using ObjectOutputStreams . Remember that ObjectOutputStreams will cache all objects written for them, so if the same object is written again in the future, it can write a backlink instead of re-writing the entire object. This is necessary when writing a graph of objects.
Your code snippet:
if (req.getRequest().equals(Request.GET_CARS)) { Response response = new Response(); response.setCars(manager.getAvailableCars()); out.writeObject(response); continue; }
records the object returned by manager.getAvailableCars() . The next time the request is received, the same object will be recorded (but now with different content), but ObjectOutputStream does not know about the new content, so it just writes a backlink. ObjectInputStream at the other end sees a backlink and returns the same object that it read the last time, that is, the original data.
You can fix this by calling ObjectOutputStream.reset() after each response. This will clear the stream cache.
source share