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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:52:00+00:00 2026-05-21T08:52:00+00:00

What state is a Java thread in after you call join with a timeout

  • 0

What state is a Java thread in after you call join with a timeout value, and the timeout passes. So for instance you have the following code:

Thread thread = new Thread();
thread.start();
thread.join(TIMEOUT);

and the timeout passes and the thread hasn’t returned what is the state? What do I need to be aware of to make sure I don’t leak threads. My initial assumption is that after the join call doing something like:

if (thread.isAlive())
{
   thread.interrupt();
   thread = null;
}

To check if the thread is still running and if so interrupt it, and then null it out to make sure it gets garbage collected.

  • 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-21T08:52:01+00:00Added an answer on May 21, 2026 at 8:52 am

    The Javadoc states that the join(time) function will wait at most that many milliseconds for the thread to die. In effect if the timeout passes your code will stop blocking and continue on. If you are worried about ‘leaking threads’ in this case you probably should redesign so that you don’t have to join the thread and can observe the state of the running thread. Furthermore calling an interrupt on the thread is bad mojo.

    class MyThread extends Thread {
        private boolean keepRunning = true;
        private String currentStatus = "Not Running";
        public void run() {
            currentStatus = "Executing"
            while(keepRunning)
            {
               try {
                   someTask()
                   currentStatus = "Done";
               } catch (Exception e) {
                   currentStatus = "task failed";
                   keepRunning = false;
               }
            }
        }
    
        public stopThread() {
           keepRunning = false;
        }
    }
    

    Above might be a better example to work off of to work with threads. You need not set the thread to null explicitly, but for example if you’re storing threads in an ArrayList remove it from the list and let Java handle it.

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

Sidebar

Related Questions

A Java thread is always in one of the following ten states: NEW: Just
According to Java thread state info calling wait() will result a thread to go
basically i have (state, state code) pairs, that are subsets of country [USA] ->
The release notes for Java NIO (in Java 1.4+) state that support for direct
Let me state up front that I have an infantile understanding of Monads. I
First let me state that, despite being a fairly new practitioner of TDD, I'm
I have a thread running under tomcat which creates a HttpUrlConnection and reads it
I'm looking for a java thread-pool, that won't run more threads simultaneously than there
I am going through a java 6 book. A sample code snippet is given
I am working on Java multithreading , where I am starting 4 threads after

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.