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 8569727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:24:12+00:00 2026-06-11T18:24:12+00:00

I have one thread (thread a) in the server that is executing object =

  • 0

I have one thread (thread a) in the server that is executing object = ois.readObject();. When I pull out the LAN wire from the client, this thread does not get an exception and is continuing reading from the stream.

Another thread (thread b) on the server is trying every one second to write one byte to the client in order to check if the connection is still alive: checkingStream.writeObject(b);

when I pull this wire, I get an IOException from checkingStream.writeObject(b);. I would like “thread b” to cause “thread a” to stop reading from the stream and proceed in code / throw an exception.

threadA.interrupt(); does not do work. What shall I do?

  • 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-11T18:24:14+00:00Added an answer on June 11, 2026 at 6:24 pm

    When I pull out the LAN wire from the client, this thread does not get an exception and is continuing reading from the stream.

    Well I would say that this is correct behaviour. The internet (in general) and IP-based networking protocols are designed to be resilient to local interruptions … like disconnection from the network.

    The problem in your case is that nothing that the reading thread is doing is telling the network stack that it expects data do be delivered every second. So the network stack cannot tell whether there is an issue with the network … or the remote service … or no data for 1 second is simply normal behaviour.

    The solution is either to set a read timeout as EJP recommends, or to remove your stuff aimed at detecting that the network is there all of the time. I recommend the latter. Unless you have an overriding application-specific need to know that the network is always there, it is just best to ignore any short term network interruptions, and/or design your application-level protocols to be resilient.


    threadA.interrupt(); does not do work. What shall I do?

    Read timeouts are one option. Another way to unjam the blocked read call is to have another thread call close() on the Socket. That will cause any pending reads or writes on Java streams associated with the socket to terminate with an exception.


    About read timeouts:

    but other answers in this forum say it is unsafe

    What is unsafe it trying to continue using a socket after you have received a timeout exception on it. If you use timeouts, you need to throw away the connection and create a new one after a socket-level timeout.

    If you don’t want to do this, then you need to implement your timeouts in a different way. For instance, create a new thread that monitors the state of the reading thread and the data that it reads. If the new thread detects no activity from the reading thread, it can raise the alarm … while leaving the reading thread blocked in the read call in case the connection springs back into life.

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

Sidebar

Related Questions

I have a server that receives various xml messages from clients (one thread per
I have one thread that is receiving data over a socket like this: while
Let's say that I have the following code that's run in one thread of
I have a socket server that used threading to open a thread for each
I have a Server class which it basically waits for connections from a client.
I have to write simple client-server application that uses Unix datagram socket. Client may
I have a Iphone app with 2 threads. One is listening to the server,
Is openpyxl thread safe? I'm hoping to have one thread changing the worksheet while
I have a list where one thread just does push_back and other thread occasionally
Assume I have one threadpool and each thread is running following method: void runMe(HashMap

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.