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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:42:21+00:00 2026-06-11T10:42:21+00:00

I am new to Java concurrecny and I am reading this at the moment:

  • 0

I am new to Java concurrecny and I am reading this at the moment: Java Tutorial-Interrupts But I can’t really understand where and why I should use an Interrupt. Can someone give me an example (code) so I better understand it? thx

  • 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-11T10:42:22+00:00Added an answer on June 11, 2026 at 10:42 am

    Interrupts are used when you want to (cough) interrupt the thread — typically meaning stop it from operating. Thread.stop() has been deprecated because of various issues so Thread.interrupt() is the way that you tell the thread that it should cease running — it should cleanup what it is doing and quit. In reality, the programmer can use the interrupt signal on a thread in any way that they want.

    Some examples:

    • Your thread might be sleeping for a minute and then spidering a web-page. You want it to stop this behavior.
    • Maybe you have a thread which is consuming from a queue of jobs and you want to tell it that no more jobs are coming its way.
    • Maybe you have a number of background threads that you want to interrupt because the process is shutting down and you want to do so cleanly.

    There are certainly many ways to accomplish the above signaling but interrupt can be used.

    One of the more powerful ways that Thread.interrupt() affects a running thread is by throwing InterruptedException from a couple different methods including Thread.sleep(), Object.wait(), and others.

    try {
       Thread.sleep(1000);
    } catch (InterruptedException e) {
       // i've been interrupted
       // catching InterruptedException clears the interrupt status on the thread
       // so a good pattern is to re-interrupt the thread
       Thread.currentThread().interrupt();
       // but maybe we want to just kill the thread
       return;
    }
    

    Also, often in a thread we are looping doing some task and so we check for interrupt status:

    while (!Thread.currentThread().isInterrupted()) {
        // keep doing our task until we are interrupted
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

it's realy rare error for me but.. It's error. Can't understand why. error just
I'm relatively new to concurrency in Java (still have yet to read JCIP, but
This is a modification of code from the Java tutorial on Concurrency package threads;
I start learning some java concurrency concept ans put in use. But one of
I was reading this Freuqent Java concurrency problems question and got confused by an
I am reading this book called Java Concurrency in Practice and the author gives
Reading this DZone article about Java concurrency I was wondering if the following code:
When I start a new Java project in eclipse, the first popup screen allow
We are starting a new Java EE project and am looking for suggestions regarding
When creating a new Java project in IntelliJ IDEA, the following directories and files

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.