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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:12:10+00:00 2026-06-05T12:12:10+00:00

So I have a "tricky" question, I want to see people opinions. I’m programming

  • 0

So I have a "tricky" question, I want to see people opinions.

I’m programming a component, which extends a JPanel and do some custom stuff.
Inside that component I have a Thread, which loops forever like this:

//chat thread
    Thread chat_thread = new Thread(new Runnable(){
        public void run(){
            while(true){
                //get chat updates
            }
        }
    });
    chat_thread.start();

So the question is, when the component is removed from its parent by the remove() method, is this thread still alive, or does it die when you remove the component?

EDIT:
Thanks all for your replies, indeed the thread does not terminate removing its starter, so in order to terminate this thread from another component, I did the following:

Set<Thread> t = Thread.getAllStackTraces().keySet();
    Iterator it = t.iterator();
    while(it.hasNext()){
        Thread t2 = (Thread)it.next();
        if(t2.getName().equals("chat_thread")){
            t2.interrupt();
        }
    }

by first creating a name for my thread with the Thread.setName() method.
Thanks!

  • 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-05T12:12:13+00:00Added an answer on June 5, 2026 at 12:12 pm

    It will still be alive. A running thread constitutes a root for the GC. Averything reachable from a chain of references starting from a root is not eligible to GC. This means, BTW, that your panel won’t be GCed either, since the thread holds an implicit reference to the panel (EnclosingPanel.this).

    You need to make sure to stop the thread when you don’t want it running anymore.

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

Sidebar

Related Questions

I have the string "re\x{0301}sume\x{0301}" (which prints like this: résumé) and I want to
Context I'm trying to have some "plugins" (I'm not sure this is the correct
I have this: (gc "$env:a.txt") -replace 'aaa', 'bbb' I want to pipe it someway
I have a string input = "maybe (this is | that was) some ((nice
I have "I love Suzi and Marry" and I want to change "Suzi" to
I have this "new" table in my database: event_comment_oauth_service which is an many-to-many relation
I have string {"1":"[4,11,14,19,20,18,27]"} . I want to change it into {\1\:\4,11,14,19,20,18,27\}. Below is
I have a "simple" 4 class example that reliably shows unexpected behavior from java
Arrays have a "length" property by default. Can I add custom properties to them?
I have the typical HTML "contact me" page, i.e. name, e-mail address and message.

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.