So, I have a "difficult" question, I want to see the opinions of people.
I am programming a component that extends JPanel and does some custom stuff. inside this component I have 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 whether the component is removed from the parent by the remove() method, is this thread still alive, or does it die when the component is removed?
EDIT: Thanks to everyone for your answers, indeed, the thread does not stop removing the starter, so to complete 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(); } }
first creating a name for my thread using the Thread.setName () method. Thanks!
source share