Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6796509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:29:51+00:00 2026-05-26T18:29:51+00:00

Forgive the pseudocode – my wireless networks is down, and I can’t copy the

  • 0

Forgive the pseudocode – my wireless networks is down, and I can’t copy the code from my offline computer onto StackExchange at the moment.

I have two java applications, connected via java.net.* sockets. I am trying to pass “Message” objects from one to the other with via objectinput/output streams.

Here’s what I’m doing:

Class Message implements Serializable
{
  String text
  int data
     public Message(String txt, int dat)
     {
      this.text = txt;
      this.data = dat;
     }
     string toString()
     {
      return text + " " + data;
     }
}

Server:

Server has a Queue called Outbox

for(int i = 0; i < 1000; i++)
 { 

 Message adding = new Message("Hello!",i);
 Outbox.add(temp)
 Message temp =     Outbox.poll();
 out.writeObject(temp);
  system.out.println(temp)
 }

Client:

for(int i = 0; i < 1000; i++)
{
  Message temp;
  temp = in.readObject()
  system.out.println(temp)
}

Now I hope it’s apparent that I expect the consoles of each program to look identical. Instead, this is what I’m geting.

Server

Hello 0
Hello 1
Hello 2
Hello 3...

Client

Hello 0
Hello 0
Hello 0
Hello 0...

So it looks like the Message Objects are being read but not removed from the Stream.

How can I unclog my streams and get them synchronized, as expected?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:29:51+00:00Added an answer on May 26, 2026 at 6:29 pm

    the classic cause of this problem is sending the same object reference multiple times. the Object stream impls preserve object reference identity and on the receiving end you will get the same object back on each readObject() call (even if you have modified the object on the sending side!). your pseudo code is correct, however the question is whether or not it accurately reflects your actual code.

    if your problem is a reference problem, you can solve the problem by either sending different object instances each time, or usingwriteUnshared() and/or calling reset() between each writeObject() call. using writeUnshared() will force the main object to be a new object instance on the receiving end, but other objects which may be referenced by this object may still be shared references. on the other hand, calling reset() will flush all cached objects on the receiving end, so all object references on the receiving end will be new references. which one is better for managing the data over the wire is up to your use case, however, for long-running streams, it’s always good to periodically call reset(), as this will free up memory which will build up over time (this is a common, but subtle “memory leak” when using Object streams).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive me for asking such a novice question, but I can't figure out how
Forgive me for this is a very simple script in Bash. Here's the code:
Bit of a strange one this. Please forgive the semi-pseudo code below. I have
Forgive me coder for I have sinned. I put some code into a dll
Forgive the title, wasn't sure what to put. I have some code like: var
Forgive me for the (probably) stupid question, but I'm messing around with this code
Forgive the vague title, I wasn't sure how to describe it. If you have
Forgive my ignorance - still learning here. I am using Eclipse Ganymede (Java 1.5)
Forgive me for probably using the wrong term for this application mode. Our application
Forgive me for a potentially silly question here, but in other programming languages (scripting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.