• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread in Thread

 
Drew Lane
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?
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • 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.
 
Peter Lawrey
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.
 
Angel Taveras
Ranch Hand
Posts: 84
Eclipse IDE Hibernate 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!