• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

On thread calling

 
Naveen Zed
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
code given in phazam today is


and the answars given are
1. Compile time error, the line that creates a new Thread is faulty.
2. Compilation and output of run1 and run2, but the order cannot be determined.
3. Compilation and output of run1 followed by run2
4. Compilation and output of run2 followed by run1

My problem is, Why the answar is not 2?Can't be main thread interrupted and the chance given to the other thread (started with lb2) ,before the run() method print run 1.Why there is no probability of printing run2 before run1?
 
prashanth kumar
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Naveen Zed:
code given in phazam today is


and the answars given are
1. Compile time error, the line that creates a new Thread is faulty.
2. Compilation and output of run1 and run2, but the order cannot be determined.
3. Compilation and output of run1 followed by run2
4. Compilation and output of run2 followed by run1

My problem is, Why the answar is not 2?Can't be main thread interrupted and the chance given to the other thread (started with lb2) ,before the run() method print run 1.Why there is no probability of printing run2 before run1?



When you say,"lb.run();",you are NOT creating a new thread but you are making a method call...And since its executing in the same thread,its a synchronous method call...so main thread wont continue,till the method returns..
And hence the answer..

Hope This helps
 
Naveen Zed
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I understood the situation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic