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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:15:27+00:00 2026-06-18T00:15:27+00:00

If I have a function with a try/finally section, and the thread running it

  • 0

If I have a function with a try/finally section, and the thread running it is interrupted while in the try block, will the finally block execute before the interruption actually occurs?

  • 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-18T00:15:28+00:00Added an answer on June 18, 2026 at 12:15 am

    According to the Java Tutorials, “if the thread executing the try or catch code is interrupted or killed, the finally block may not execute even though the application as a whole continues.”

    Here’s the full passage:

    The finally block always executes when the try block exits. This
    ensures that the finally block is executed even if an unexpected
    exception occurs. But finally is useful for more than just exception
    handling — it allows the programmer to avoid having cleanup code
    accidentally bypassed by a return, continue, or break. Putting cleanup
    code in a finally block is always a good practice, even when no
    exceptions are anticipated.

    Note: If the JVM exits while the try or catch code is being executed, then
    the finally block may not execute. Likewise, if the thread executing
    the try or catch code is interrupted or killed, the finally block may
    not execute even though the application as a whole continues.

    class Thread1 implements Runnable {
    
        @Override
        public void run() {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                System.out.println("finally executed");
            }
        }
    }
    

    …

    t1.start();
    t1.interrupt();
    

    It prints – finally executed

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

Sidebar

Related Questions

So I have this function: (define (try try-block catch-block finally-block) ; Implements try/catch/finally like
I have a function with try, catch and finally block. If an exception is
this is so that I will have to build a delete function, I try
I would like to perform a progress indicator during request. I have try function
I have a code like that: User = function(){} User.a = function(){ return try;
I try to have some inheritance with attributeBindings between two View. (function(exports) { Ember.MobileBaseView
I have this static callback function in MyClass, and I try to call another
I have a function to execute a query and return a scalar value like
I have this function implemented for parsing employee details, similarly i will have to
I have a function which takes a string of commands to execute and makes

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.