After a thread gets access to the CPU and executes some instructions in its run method, the thread can lose access to the CPU in several ways. Describe three ways, and how the threads are resumed. What is context switching?
What will be an ideal response?
* Time-out: Most computers running Java programs automatically time out a running thread every few milliseconds. The process of automatically timing out, called time slicing, pauses the running thread's execution and sends it to the rear of the ready queue. The thread at the front of the ready queue is given access to the CPU.
* Sleep: A thread can be put to sleep for a given number of milliseconds. When the thread wakes up, it goes to the rear of the ready queue.
*Block: A thread can wait for some event, such as user input, to occur. When a blocked thread is notified that an event has occurred, it goes to the rear of the ready queue.
* Wait: A thread can voluntarily relinquish the CPU to wait for some condition to become true. A waiting thread can be notified when the condition becomes true, and move again to the rear of the ready queue.
Context switching is the process of saving and restoring a thread's state so that when the thread returns to the CPU, its run method can pick up where it left off.
You might also like to view...
Which of the following is the process of combining data from multiple databases or data sources in a central location for analysis?
A. data deduplication B. data warehousing C. cloud storage D. data mining
Mainframes' processing speed is measured in flops.
a. true b. false