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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:12:24+00:00 2026-06-03T19:12:24+00:00

I have a Simple Multithread Server, the code of Threads looks like this: public

  • 0

I have a Simple Multithread Server, the code of Threads looks like this:

public void run(){

 while(Ecoute()){

     str=LireTrame(this.socClient);//read text byte by byte 

    //some code here

    Dormir(500);//Sleep for 500ms  
   }     


}

I’d like to create a timeout of 3 minutes, if a client socket does not send a message in 3 minutes, the thread must be closed…

so I try that:

 public void run(){

        try {
        socClient.setSoTimeout(180000);//timeout for 3 min...
    } catch (SocketException ex) {
        Logger.getLogger(tache.class.getName()).log(Level.SEVERE, null, ex);
    }


 while(Ecoute()){

     try{
      str=LireTrame(this.socClient);//read text byte by byte 
    }
    catch(java.net.SocketTimeoutException ex){
     log.append("timeout exception has benn catched \n") ;
     break;//break the while
   } 

    //some code here

    Dormir(500);//Sleep for 500ms  
   }     


}

the problem is that netbeans display an error message:
enter image description here

java.net.SocketTimeoutException never thrown in body of corresponding try statement

I tried this with SocketException but same result..

why i can’t catch them ?

UPDATE: based on responses from thinksteep and mprabhat, I added th throw in LireTrame(..) but still i can’t catch the Exception:

 public  String LireTrame(Socket socClient) throws java.net.SocketTimeoutException{
 int c = 0;
  String Nmea="";
boolean finL=true;
 do{
            try {
                c=socClient.getInputStream().read();
            } catch (IOException ex) {
                Logger.getLogger(tache.class.getName()).log(Level.SEVERE, null, ex);
            }
    char ch=(char)c;

    Nmea=Nmea+ch;
    if(ch==';')
        finL=false;

  }while(finL);
 return Nmea;
 }



mai 11, 2012 8:04:02 PM Daemon.tache LireTrame
Grave: null
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at java.net.SocketInputStream.read(SocketInputStream.java:203)
    at Daemon.tache.LireTrame(tache.java:232)
    at Daemon.tache.run(tache.java:87)
    at java.lang.Thread.run(Thread.java:722)

are there any ideas to make this otherwise?

  • 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-03T19:12:32+00:00Added an answer on June 3, 2026 at 7:12 pm
    =LireTrame(this.socClient);//read text byte by byte
    

    should throw SocketTimeOutException. You didn’t post code for this method, but I am assuming it is not throwing SocketTimeOutException which is why netbeans highlighting.

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

Sidebar

Related Questions

I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have a simple question, how to convert this server into multithreded as far
I have a very simple crawler. I want to make my current code run
Some APIs, like the WebClient, use the Event-based Async pattern . While this looks
I have a code. like this: int functionA (){ Foo(**,**,**); return 0; } Foo()
I am new to multithread programming, please don't laugh if this seems too simple.
I have created a .Net application to run on an App Server that gets
I have a simple multithreaded C# server and client. When just one client is
I have a main processes that will create 4 threads. If i simply run
I have to write a simple chat in C. One program is a server

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.