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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:15:20+00:00 2026-05-28T03:15:20+00:00

If i have a thread something like this: Thread t = new Thread(myThread); t.start();

  • 0

If i have a thread something like this:

Thread t = new Thread(myThread);
t.start();

private static Runnable myThread = new Runnable() {
    public void run() {
        try{
            String line=null;
            while ((line = eStream.readLine()) != null){
                //do something
            }
         }
         catch (Exception e){}
    }
};  

Now what happens in while loop, at times the readLine() is hanged because it is expecting input from external process. So in that case what i am trying to do is to setup a timer and if it expires, i interrupt this thread t with t.interrupt();

Now when i try to catch InterruptedException after the try block, i am getting compile time error. Can someone tell me in this scenario, how can i catch Interrupted Exception?

Thank you

  • 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-28T03:15:21+00:00Added an answer on May 28, 2026 at 3:15 am

    interrupt won’t free a blocking readLine() call. You have to close the stream to do that.

    You are catching the InterruptedException already (and ignoring it) with this line

    catch (Exception e){}
    

    This won’t work

    line = eStream.readLine().toString()
    

    As it will throw a NullPointerException when you reach the end of file. Remove the .toString()

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

Sidebar

Related Questions

i need a thread safe map, i have something like this: (i'm very new
In Java, I would do something like: Thread t = new MyThread(); t.start(); I
I have something like this: private void DoSomething() { System.Console.WriteLine(Creating Foo); Foo result =
I have a thread implemented inside a class using runnable like this: static Runnable
I have a simple server that looks something like this: void *run_thread(void *arg) {
I have extended threading.Thread - my idea is to do something like this: class
I am pretty new to thread-safe programming, and was wondering if I have something
I have a quad processor. I coded something like that in java; Some.java; public
I have a list in C that is something like this: typedef struct _node
I have a method that looks like this: protected void OnBarcodeScan(BarcodeScannerEventArgs e) { //

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.