June 2006
Intermediate to advanced
1344 pages
42h 52m
English
Figure 15.3 shows how to construct Thread objects and demonstrates class Thread’s Shared method Sleep. The program creates three threads of execution, each with the default priority Normal. Each thread displays a message indicating that it is going to sleep for a random interval of from 0 to 5000 milliseconds, then goes to sleep. When each thread awakens, it displays its name, indicates that it is done sleeping, terminates and enters the Stopped state. You will see that method Main (i.e., the Main thread of execution) terminates before the application terminates. The program consists of method Main (lines 6–33), which creates the three threads, and class MessagePrinter (lines 36–59), which defines a Print ...
Read now
Unlock full access