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

  • Home
  • SEARCH
  • 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 8823241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:18:13+00:00 2026-06-14T06:18:13+00:00

I have a client/server application in Java, which communicate by serialize/deserialize objects. Typically client

  • 0

I have a client/server application in Java, which communicate by serialize/deserialize objects. Typically client sends RequestObj, and server responds with ResponseObj. Server also send heartbeat RequestObj, and client responds with heartbeat ResponseObj.

//Sample RequestObj
public class RequestObj implements Serializable {
   private static final long serialVersionUID = xxxx;  //auto generated
   int type; //TYPE_HEARTBEAT
   long time;
   ...

   public void setTime() {
      this.time=System.currentTimeMillis();
   }
}

When sending heart beat request from the server to each client, it reuse the same RequestObj (per connection), set with current time, and then send to the client. I am expecting to receive the RequestObj with the currect time. However, it seems the RequestObj deserialized at the client always give me the wrong time. In fact the RequestObj received the client is exactly the same (same object id/address) as the first heartbeat RequestObj. But the time in not updating?

//Sample Server side code sending heartbeat
public class ServerSocketWrapper {
   Socket socket;
   ObjectOutputStream oos;
   ...
   RequestObj heartbeat = New RequestObj(TYPE_HEARTBEAT);

   public void sendHeartBeat() {
      heartbeat.setTime();
      logger.info("HeartBeat {} {}", heartbeat.time, formatFullTime(heartbeat.time));
      oos.writeObject(heartbeat);
      oos.flush();
   }
}

Here is some sample client code:

//Sample Client side code receiving heartbeat
public class ClientSocketWrapper {
   Socket socket;
   ObjectInputStream ois;
   long heartbeatTime;
   ...

   public void run() {
      while(true) {
         Object obj = ois.readObject();
         if (obj instanceof RequestObj) {
            RequestObj req = (RequestObj) obj;
            if (req.type == TYPE_HEARTBEAT) {
       heartbeatTime = req.time;
               logger.info("Received heartbeat {} {} {}", heartbeatTime, formatFullTime(heartbeatTime), req);
               sendResponse(new ResponseObj(req.id, TYPE_HEARTBEAT));
            }
         }
         ...
      }
   }
}

Here are the logs

logs on the server
16:33:56.186 [pool-2-thread-2] INFO  ServerSocketWrapper - HeartBeat 1352842436186 2012-11-13 16:33:56.186
16:34:56.185 [pool-2-thread-2] INFO  ServerSocketWrapper - HeartBeat 1352842496185 2012-11-13 16:34:56.185
16:35:56.185 [pool-2-thread-1] INFO  ServerSocketWrapper - HeartBeat 1352842556185 2012-11-13 16:35:56.185

logs on the client
16:34:08.510 [server:port] INFO  ClientSocketWrapper - Received heartbeat 1352842436186 2012-11-13 16:33:56.186 RequestObj@8497904
16:35:06.758 [server:port] INFO  ClientSocketWrapper - Received heartbeat 1352842436186 2012-11-13 16:33:56.186 RequestObj@8497904
16:36:10.303 [server:port] INFO  ClientSocketWrapper - Received heartbeat 1352842436186 2012-11-13 16:33:56.186 RequestObj@8497904

Why the time received on the client side is not updating? Is JVM doing some sort of object caching? Server is running w/ jdk 1.7.07 64b, while client on jdk 1.6.31 64b.

  • 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-06-14T06:18:14+00:00Added an answer on June 14, 2026 at 6:18 am

    If write a single object more than once using the same ObjectOutputStream, the ObjectOutputStream will recognize that it has already seen that object and encode it as a reference to the existing object. This is how serialization is able to preserve reference aliasing.

    If you don’t want reference tracking across messages, construct a new ObjectOutputStream and ObjectInputStream pair for each new message (or #reset the ObjectOutputStream and #readUnshared from the ObjectInputStream). If you don’t do either of these, but instead never modify and reuse message objects, you won’t have the problem of modifications not being seen, but you’ll instead leak resources since the ObjectInputStream will hold a strong reference to every object it’s ever deserialized.

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

Sidebar

Related Questions

I have a client Server application which communicate using objects. when I send only
I have a basic client/server application written in Java which uses plain Sockets for
I have written a java client server application (not http), which i need to
I have created a TCP server-client application in java which exchange periodic messages between
I have developed a java swing client-server application. The server has many services like
Background: I have written a java swing based client server application. The server is
I have a client server application in which the server and the client need
I have a client server application in which I need to transmit a user
I have a server application in Java which has two simple operations, addTwoInts and
I have created TCP Server application in Java, and a client application in C#.

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.