I\'m trying to understand thread basics, and as a first example I create two thread that write a String on the stdout. As I know the scheduler allows to execute the threads
Each instance of the PingPongThread
is synchronising on itself and not on a shared resource. In order to control the message passing you'll need to synchronise on a shared resource (e.g. your turn
variable ?)
However I don't think this is really going to work. I think you should check out wait()
and notify()
to do this (if you want to understand the threading primitives). See this for an example.