• Post Reply Bookmark Topic Watch Topic
  • New Topic

Create threads by Child threads showing same results as Parent.  RSS feed

 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I created Thread by main thread, it shows output like



Tmanager is thread name, 5 is the priority and main is its parent.

Now I want to create child thread for Tmanager. When I do this, the child threads created. But, it shows parent as 'main' thread instead of Tmanager as parent.



I'm expecting the result,



Can anybody explain me what's happening here?

Thanks:
Ramakrishna K.C
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your code, otherwise we can't tell you why this happens.
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Main class:



ThreadManager class:


threadmanager child threads:


child's are created by ThreadManager not by main thread. So it should show Thread[T0, 5, Tm] not Thread[T0, 5, main].

Thanks:
Ramakrishna K.C
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The third value printed to the output is not the 'parent thread' - there is no such thing as a parent thread and child threads, all threads are peers. The third parameter is the ThreadGroup, which, since you didn't change it, is still the one named "main".
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last parameter printed out by Thread.toString is the name of the ThreadGroup that the thread belongs to, not the parent thread. As you don't create any new ThreadGroups, all your threads will belong to the main ThreadGroup.
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK.. So what I'm getting the output is right.. Threads are created by ThreadManager..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!