For reference please see the sample chapter on Threads here: http://www.ii.uib.no/~khalid/pgjc3e/
I'm trying to understand the outcome of Exercise 13.6 posted in the sample chapter on Threads in the A Programmer's Guide to
Java SCJP Certification - 3rd Edition
The output I get is that R2 is printed twice and R1b is printed once. I don't understand why R2 is being printed twice (instead of just once).
From logically thinking about the outcome, it appears that R2 is printed once (when the
thread starts the first time, which invokes R2's run() asynchronously at some point)
then what causes R2 to be printed again?
Is it because of this line? :
because the code in the sample never called new Thread(new R1(),"|R1a|").
start() , so the R1 thread will never start running.
so calling the run() method manually in R1 , is just that (it is not a thread execution) , so the current thread it prints is R2 ?