DEV Community

Discussion on: Multithreading in Java for dummies (part 2)

Collapse
 
codeismail profile image
Ismail Ibrahim

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.

Collapse
 
raulavila profile image
Raúl Ávila

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?

Collapse
 
codeismail profile image
Ismail Ibrahim

Exactly. I thought so too. It works well with 10.👍