To illustrate what we have covered so far, we introduce a Java application,
PrintNumbersThread,
which includes thread code that simply lists the numbers 1 to i0. The application will have
two thread instances; the thread will append the thread instance name to the output number
so that we can distinguish between the instances. Finally, we will use the sleep method within
the thread's run method to cease execution every half-second so that we can interleave the two
thread instances' output.
PrintNumbersThread
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class PrintNumbersThread ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.