| Author |
On thread calling
|
Naveen Zed
Ranch Hand
Joined: Aug 11, 2006
Posts: 61
|
|
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
Joined: Mar 22, 2004
Posts: 162
|
|
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
|
SCJP1.5(86%)<br />SCWCD1.4(95%)<br />SCBCD1.3(92%)<br />IBM 252
|
 |
Naveen Zed
Ranch Hand
Joined: Aug 11, 2006
Posts: 61
|
|
|
Thank you, I understood the situation.
|
 |
 |
|
|
subject: On thread calling
|
|
|