• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When a Thread Dies

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a question about the lifetime of a thread and the Garbage Collector.
If I have something like the following:

And then somewhere else in my code I have:
MyThread thread = new MyThread();
thread.start();
So the thread runs, but it is not a infinite loop so when the execution ends inside the thread, does the thread die? And then is the thread object available for the Garbage Collector?
In case you are wondering why I am running a thread that does not have an infiniate loop of any kind like most threads probably will, I am using the SwingUtilities.invokeLater() from a JButton actionEvent in quering a Database that takes a little time, I don't want the ActionEvent to be hung up on waiting for that process to finish, but it does finish. So the thread should end.
Anyway, that is my question.
Thanks
[ July 31, 2002: Message edited by: Gregg Bolinger ]
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The thread dies when the run() method exits, and, like any other object, the thread and Runnable object are each eligable for GC when there are no reference to it (except from other object eligable for GC).
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Threads die when the run method ends. If you never started the thread, then the thread object will die when the thread group it belongs to dies.
Using swingInvoke later does not actually create a new thread, it just executes the Run method of your object inside of the swing thread, later
 
Arthur, where are your pants? Check under this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic