• 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

Create threads by Child threads showing same results as Parent.

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK.. So what I'm getting the output is right.. Threads are created by ThreadManager..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic