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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:42:13+00:00 2026-06-14T20:42:13+00:00

Here is a snippet from a little program I am making using threads. JOptionPane.showMessageDialog(null,

  • 0

Here is a snippet from a little program I am making using threads.

JOptionPane.showMessageDialog(null, "Before: " + thread.isAlive());
if (!thread.isAlive()) {
    JOptionPane.showMessageDialog(null, "Thread is not alive.");
    thread.start();
}
JOptionPane.showMessageDialog(null, "After: " + thread.isAlive());

This code is activated using a button. When I press the button the first time, I correctly get “Before: false” and then “After: true”.
When I press the button again, I incorrectly get “Before: false” and then “After: true”, but expect Before: true, since I am not destroying the thread or overriding the variable.

I believe that this is what is causing IllegalStateException which I am getting (correct me if I am wrong on that too!)

Can anyone explain to me what I am doing wrong?

EDIT:

public class SomeClass extends Applet
{

private ClassThatExtendsThread thread;

public void init()
{
    super.init();

    //Some UI elements are created here.

    thread = new ClassThatExtendsThread (/*there are some parameters*/);
} 
  • 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-14T20:42:14+00:00Added an answer on June 14, 2026 at 8:42 pm

    Once a thread has completed running it is considered dead. Calling isAlive on the same thread at this point will always return a result of false. The JavaDoc for Thread does mention this:

    public final boolean isAlive()
    
    Tests if this thread is alive. A thread is alive if it has been started and has not
    yet died.
    

    If you are not re-instantiating your thread instance in-between calls to your code snippet then you will definitely get an IllegalStateException. This is because you attempt to start a thread that has already been terminated:

    if (!thread.isAlive()) {
        JOptionPane.showMessageDialog(null, "Thread is not alive.");
        thread.start();
    }
    

    For future reference, note that you can query a thread state via the getState method, which should help with analyzing errors, at the least.

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

Sidebar

Related Questions

I am creating little blog app. Here is a snippet from my views: views.py
Here is a little snippet of code from Wikipedia's article on malloc(): int *ptr;
Here's a snippet from my application: class PortolioItem(models.Model): ... user = models.ForeignKey(User) contract =
Here is a snippet from a Sinatra app where users will be submitting urls.
First things first, here is a little snippet code to help explain my problem:
I'm using this little jewel of a Django code snippet to edit a ManyToManyField
I have this little code snippet, but it's not really working right now. I
I need a little help with the JProgressBar component. My program copies files from
Here's my code: // Not all headers are relevant to the code snippet. #include
I once saw this nice little snippet of code below, here at SO: template<typename

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.