+ 2

A litle Help here!!!

Can anyone tell me why my code doesn't work as I expect. I think first thread should start first. But second always comes first. Where's the problem? https://code.sololearn.com/cy8sX5vpqx0p/?ref=app

30th Nov 2017, 12:10 AM
Taabeer Murtaza
Taabeer Murtaza - avatar
2 Answers
+ 2
Basically, each thread is working on its own thing and sending you output. This is actually happening on their server, so you'll get whatever order happens to come back quickest since it's not outputting from the same thread. If you keep running it, you should see a randomish order, sometimes 2nd one returned quicker and others 1st did. Sometimes you see a thread pump out a couple in a row before the other gets a chance.
30th Nov 2017, 12:42 AM
AgentSmith
+ 2
So is this important to schedule each Thread and wait for the other? I mean in this demo code. Should I improve it?
30th Nov 2017, 2:23 AM
Taabeer Murtaza
Taabeer Murtaza - avatar