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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:08:37+00:00 2026-06-12T06:08:37+00:00

Both cause a program to stop executing. It’s clear that there must be some

  • 0

Both cause a program to stop executing. It’s clear that there must be some differences in how this happens, though. What are they?

  • 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-12T06:08:38+00:00Added an answer on June 12, 2026 at 6:08 am

    Summary

    1. thread.interrupt() does not stop a thread. It is used for coordination in multi-threaded programs. Don’t use it unless you know exactly what you do.
    2. Throwing a RuntimeException will (usually) terminate the thread but not necessarily the program.
    3. System.exit(int) almost always terminates the program and returns a status code.
    4. In unusual situations, System.exit(int) might not actually stop the program. Runtime.getRuntime().halt(int) on the other hand, always does.

    Thread Interruption

    I’m afraid your first sentence is wrong. Thread.currentThread().interrupt() does not stop the thread or the program.

    Interrupting a thread is a way to signal that it should stop, but this is a cooperative effort: The code in the thread is supposed to check the interrupted status from time to time and (in most cases – but even this is only optional) should stop if is has been interrupted. If it doesn’t do that nothing will happen.

    Specifically, interrupting a thread (any thread, include the currently executing one) will only set the interrupted flag. Certain methods in the standard library will throw an InterruptedException, but this is also just a way to signal that the thread has been interrupted. What should be done in such a situation is up to the code running in that thread.

    Here are the relevant parts from the Java Concurrency in Practice book by Brian Goetz:

    Thread provides the interrupt method for interrupting a
    thread and for querying whether a thread has been
    interrupted. Each thread has a boolean property that
    represents its interrupted status; interrupting a thread sets
    this status.

    Interruption is a cooperative mechanism. One thread cannot
    force another to stop what it is doing and do something
    else; when thread A interrupts thread B, A is merely
    requesting that B stop what it is doing when it gets to a
    convenient stopping point if it feels like it.While there
    is nothing in the API or language specification that demands
    any specific application level semantics for interruption, the
    most sensible use for interruption is to cancel an activity.
    Blocking methods that are responsive to interruption make it
    easier to cancel long running activities on a timely basis.

    Exceptions and System.exit(int)

    The Javadoc of System.exit(int) says:

    Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

    So calling exit() will (almost) definitely stop your program. In contrast to throwing a RuntimeException (or an Error), this can not be caught somewhere down the call stack and it does also not depend on whether there are other threads running. On the other hand, an uncaught exception terminates the thread in which it was thrown, but if there are any other (non-daemon) threads, the program will continue to run.

    Another difference to throwing an Exception is that exit() will not print anything to the console (as does an uncaught exception) but instead makes the program return a specific status code. Status codes are sometimes used in shell or batch scripts but other than that, they are not very useful.

    Runtime.halt(int)

    Finally (for completeness’ sake), I’d like to point out a third possibility to exit a Java program. When System.exit(int) is called (or the program ends in some other way), the runtime does some cleanup work before the Java Virtual Machine is halted. This is described in the Javadoc of Runtime.exit(int) (which is called by System.exit(int):

    The virtual machine’s shutdown sequence consists of two phases. In the first phase all registered shutdown hooks, if any, are started in some unspecified order and allowed to run concurrently until they finish. In the second phase all uninvoked finalizers are run if finalization-on-exit has been enabled. Once this is done the virtual machine halts.

    If any shutdown hook or finalizer is prevented from completing, for example because of a deadlock, the program might never actually exit. The only method that guarantees that the JVM halts is Runtime.halt(int):

    This method should be used with extreme caution. Unlike the exit method, this method does not cause shutdown hooks to be started and does not run uninvoked finalizers if finalization-on-exit has been enabled.

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

Sidebar

Related Questions

I am working on a C++ program that uses some external C libraries. As
Is it possible to run both session and cookie helpers? Cause I am trying
Both of these frameworks are great, but I've noticed that Knockout likes to point
Both methods MyBehavior::CreateSerializer() are not called of some reason, but ReplaceBehavior() method is working.
We have a custom built program that needs authenticated/encrypted communication between a client and
I'm building a program in C++, using SDL, and am occasionally receiving this error:
I have a c++ program that dies because of out of memory error. Do
I am running two separate threads in C, both doing some operations. Both threads
I am writing an application that uses SSLEngine with NIO, I writing both the
I have this code that was running for about 2 hours. After that the

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.