Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Thread in Thread

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say I have two threads, A & B.

Thread A is started from the main event thread.

Thread B is started inside Thread A at the very end of its run method.

Does thread A stay alive until thread B is finished?
 
Rancher
Posts: 3626
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Not unless you put something else in A to keep it alive. But if starting B was the very last thing in A's run() method, then there's no reason for A to stay alive after that.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. If the last thing A does is create B, there actually there is no point creating B, just use A to run what B would do.
 
Ranch Hand
Posts: 84
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It could stay alive, but it's uncertain the behavior of these two threads. If you want that Thread A remain alive while Thread B it's running the you have to join them with Thread.join.
[ December 24, 2008: Message edited by: Angel Taveras ]
 
    Bookmark Topic Watch Topic
  • New Topic