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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:37:41+00:00 2026-05-20T06:37:41+00:00

When I got an incoming call then I have to immediately interrupt my long

  • 0

When I got an incoming call then I have to immediately interrupt my long running thread. I want to use Thread.interrupt() method to do that.

Reference says:

Threads blocked in an I/O operation of an InterruptibleChannel will 
have their interrupt status set and receive an ClosedByInterruptException. 
Also, the channel will be closed.

In my thread I’m downloading a file via HTTP, so I want to use InterruptibleChannel in order to immediately stop downloading. Could you give me some source code, how to download a file using InterruptibleChannel?

this solution is not okay for me, because Thread.interrupt() doesn’t interrupt blocking IO:

while ((length = httpIn.read(buffer)) > 0) {
       if(Thread.interrupted())
          ....
       else
       {
            fileOut.write(buffer, 0, length);
            fileSize += length;
       }
}
  • 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-20T06:37:42+00:00Added an answer on May 20, 2026 at 6:37 am

    One general way to interrupt a thread that is blocked doing I/O is to close the channel. For example, if a thread is blocked in a read() operation over a socket, the thread that want to interrupt it can close the socket.
    Not sure if this method will be useful for you, but its a general solution that some times it is used.

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

Sidebar

Related Questions

I'm trying to launch an activity , when i got an incoming call for
HI, I've got Windows XP Mode running on Wndows 7 Professional x64. I have
I've got a WSE 3.0 web service that I'm trying to call using a
I've got a framework that routes all incoming URIs through a base file, and
Got two applications running on tomcat: Application1 (JSP) Application2 (Webservices) I want to set
I'm trying to handle my incoming buffer and ensure that I got all the
Got a programm with 2 threads. one thread is writing some stuff into the
Got a seg fault from my memcpy that gdb can't give me anything else
got some problems. Built an applet that has to be used step-by-step. After each
Got datatable with Id, parentId, description. It is a relationial table structure. I want

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.