• 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

Child thread becoming a parent

 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible for a child thread to be a parent i.e. to spawn another thread? Or is it that the main thread is the only thread that can spawn a child thread?


main-------child------child // is this possible?
main
|-------child // or is this the only way
|-------child // to create a multiple
|-------child // child threads



I have this program that tries to do this.

1. The method m1() is suppose to create the thread B - a child of thread A
2. The join() method is there for A to wait until B completes.
But the result is not what I expect. B will complete but A will wait forever. So it seems that B is not a child of A.
[ July 03, 2003: Message edited by: Alton Hernandez ]
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem is that you are joining thread A to itself.
You need for the thread A to have a reference to the thread B and from within thread A's code do a join on the reference of thread B. When you do this.join() you are telling the running thread to wait until he has finished before he continues.
You can start a new thread from a child thread, it doesn't have to be from the main thread.
[ July 03, 2003: Message edited by: Damien Howard ]
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're right !
Thanks a lot Damien

[ July 03, 2003: Message edited by: Alton Hernandez ]
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like 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