+ 3
why the loop in threads runs 1 execution?
Help! Look my code "MultiThreading". Why instead 3 executions the loop of Thread1 and Thread2 going 1 execution in the sandbox?
3 Answers
+ 5
I am not exactly sure
After experimenting a little bit with your code I figured out problem
When you do Thread.sleep(1000) in a loop, that means that thread will go in waiting stage for 1 second, but in this time the loop completes it's running so you get to see it running only one time.
What experiment I did was changing sleep value to low, I changed it to 100 and it executed 2 times.
Hope this helps. š¤
+ 3
Thanks for answer)
- 2
Hi