If I was to call inner methods of the Thread, would it still run on a separate thread?
No. Threads aren't magic. When you call a method you are calling that method with the current thread. To fork a thread you actually have to create a thread object (or executor service) and start it. Then it calls run()
, etc..
So if you called player.pause()
you would be calling pause from the current thread which is possibly the "main" thread. Your playerThread
would be doing something else in the background. The whole reason why the pause()
method is synchronized
is so you can all it from the outside thread and the playerThread
without them overlapping. It also means that multiple threads can test and set the isPlaying
boolean and other threads will see the updates.
You should most likely start with the Java thread tutorial.