Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sandra Bachan wrote:
I was expecting main to execute first. Please clarify.
Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Sandra Bachan wrote:
Output is always the same, whether I include t2.join() or not.
Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Arjun Srivastava wrote:modify your code at line25
also use
before t1.join();
try this,and see the output.
Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Sandra Bachan wrote:
If I comment out the t1.join() method, then t1 and t2 are interleaved.
Please tell me if I understand correctly: When we say t1.join(), it gives t1 priority over t2 such that t2 must wait for t1 to finish execution before t2 begins?
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Hauke Ingmar Schmidt wrote:You have three threads running: The main thread, t1 and t2.
You are calling t.join() from within the main thread so the main thread joins t1. The behaviour of t1 and t2 can't be predicted, but "interleaved" execution is fine.
If you want a thread to join another thread then you have to call join from inside the first thread.
What's wrong? Where are you going? Stop! Read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|