This has been a great post so far. I have one worry though. I've tried using 2ms when invoking sleep() but the main thread terminates even before the thread1 and thread2 starts executing.
Raúl is a software engineer with a strong focus on code quality and readability. He likes to work following XP and Clean Code practices, and his favorite language is Java.
If I understood correctly, I think that means the Thread scheduler does not start the two "players" in those 2ms, so the main thread requests the interruption before they can enter in the loop to play. It's weird, but it can happen. Have you tried increasing the sleep time to let's say, 10 or 20ms?
This has been a great post so far. I have one worry though. I've tried using 2ms when invoking sleep() but the main thread terminates even before the thread1 and thread2 starts executing.
If I understood correctly, I think that means the Thread scheduler does not start the two "players" in those 2ms, so the main thread requests the interruption before they can enter in the loop to play. It's weird, but it can happen. Have you tried increasing the sleep time to let's say, 10 or 20ms?
Exactly. I thought so too. It works well with 10.👍