What is it specifically that you're confused about?
Basically, there are 2 threads here running concurrently. Each counts down from 5 to 1, sleeping a set (minimum) amount of time with each iteration. One thread tends to sleeps longer than the other, so it will likely take longer to finish running.
However, the exact output is unpredictable, because how the threads actually end up running is determined by the (platform-dependent) thread scheduler. In fact, you're likely to see different output from one execution to the next.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
Line 1 creates a new NewThread which calls the constructor in line 5 The constructor makes another Thread labelled "Demo Thread" in line 6. Line 7 prints the thread created in line 6. Line 8 calls the run() method on the thread in line 6. The constructor exits and line 2 starts a loop to print (line 3) the thread that is running main() which is a separate thread than the one created in the NewThread constructor. The loop waits 1 second between each println call (line 4). Meanwhile the run() method begins a loop (line 10) to print (line 11) the thread created in line 5 waiting 1/2 second between each println call (line 12). The rest is to demonstrate that the two loops (and the two threads) are running independently of each other. The results may vary (or not) each time you run the program.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt