• 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

simple doubt about Thread's Parent

 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Following is question from Sun Guoqiao's exam 2.
I am confused about the Thread's parent...!

Thread inherits the priority from it's parent Thread. In case of thread t2, which is it's parent..? t1 / main Thread..?
Thanx
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the parent thread of t2 is the main thread since t2 is not created inside t1 but t2 will just make t1 run when started.
Val
 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i agree wid Valentin , Thread t2's parent is indeed Thread main

at line1 , when t1 is created , it gets it priority from the parent main Thread ( which happen to be 5 , NORM_PRIORITY ) , at line2 t1 explicitly change this priority to 3
AT line3 , a new thread t2 is created , by passing a Runnable( Thread class implements Runnable) to constructor ( NOTE dat Thread class donot hav ne constructor which take Thread as parameter , so there is no question of t2 taking t1's priority anyway ) , This new thread t2 is created in main() method itself , so its parent is main Thread ,(the Thread , in which instance of some other Thread is made using new , is the parent of new Thread ) n it gets its priortiy 5 from main Thread only
so the line4 n line5 prints expected output as below :
3 5

hav chiliing prep n good luck !

------------------
Gagan (/^_^\)
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
very good explanation Gagan
 
swati bannore
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Gagan..It cleared my doubts..
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic