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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:46:25+00:00 2026-06-13T11:46:25+00:00

I am writing a multi-threaded java console application that I am intending to kill

  • 0

I am writing a multi-threaded java console application that I am intending to kill via Ctrl-C. In this situation, if I have a class that encapsulates a single thread is it good practice to shutdown the child thread in the encapsulating classes finalize method?

Is it possible to get artifacts of the original application left running if you Ctrl-C the original app and all threads are not shutdown properly?

pseudo code:

public class ParentClass {

Thread childThread = new Thread(new ExampleRunnable());

  @Override protected void finalize() throws Throwable {
   childThread.shutdown();
  }
}

public class ExampleRunnable implements Runnable {

 private volatile boolean alive = false;

 @Override
 public void run() {
  alive = true;
  while(alive) {
   //do some work
  }
 }

  public void shutdown() {
   alive = false;
  }
}
  • 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-13T11:46:26+00:00Added an answer on June 13, 2026 at 11:46 am

    Implementing finalize can have a terribly bad side-effect. Way back in the day, Java was slow and one of the reasons was the need to run finalize on every object ever created. Now the JVMs are smart enough to check if a non-trivial finalize implementation exists rather than blindly call it on every object being collected. Having just one class implement finalize may not be bad, but don’t make a habit of it.

    If you want to do something special during a normal shutdown of the JVM, then use a shutdown hook.

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

Sidebar

Related Questions

Here's the scenario: I have a multi threaded java web application which is running
I am writing a multi-threaded application in Java in order to improve performance over
I'm writing a multi-threaded server application in Java. Everything works fine , but there's
I am writing a multi threaded application and I have concerns with 2 threads
I am writing a multi-threaded Java program that generates lot of random numbers. Additional
For example, I'm writing a multi-threaded time-critical application that processes and streams audio in
I am writing a multi-threaded application that mimics a movie theater. Each person involved
If you are writing a multi-threaded application that uses system/library calls that make use
I have a multi threaded application that writes to a settings xml file using
I'm writing a multi-threaded Java web crawler. From what I understand of the web,

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.