Chapter 10 Flashcards
What does a threads run method do?
Executes when the thread acquires the CPU
Time slicing
-A means of scheduling threads or processes wherein each process receives a definite amount of CPU time before returning to the ready queue
-aka timing-out- running thread times out automatically, pausing the running thread’s execution and sending to rear of the ready queue
Synchronization problem
-a type of problem arising from the execution of threads or processes that share memory
-the consumer can access data that are not there, can miss data, and can access same data more than once
A sleeping thread vs a waiting thread
Sleep- can be put to sleep for a given number of milliseconds. When the thread wakes, it goes to rear of ready queue
Wait- it voluntarily relinquish the CPU to wait for some condition to become true. Thread can be notified when condition becomes true and move again to rear of rear queue
Readers/writers vs producer/consumer
unlike p/d, r/w may access the shared data in any order and there may be multiple readers and writers
How would you make the Student class from ch. 9 thread safe for readers and writers?
Student class consists of multiple get methods (read) and one set method (write). The key to making it
thread-safe is by accessing the student objects through a SharedClass object
What role do ports and IP addresses play in a client/server program?
IP address is a unique identifier of a
computer unique identifier of a computer on a network. Port is the object (channel) via which clients
connect object (channel) via which clients connect to the server.
Both are used in a client/server program as arguments for a
Socket’s method connect which is used to connect the socket to a host
computer (server) on given IP address and port specified for it.
What is a local host and how is it used to develop networked applications?
It’s a standalone computer that may or may not be connected to the internet
The localhost is a hostname (IP name) of the current computer and it is widely recognized standard.
Developers tend to use it as a test
environment for their applications
before making them public. It uses a
loopback mechanism - it is basically sending all requests back to itself.
Why is it a good idea for a server to create threads to handle clients requests?
- It makes the design of each task simpler
- Processes of separate threads can run concurrently, giving clients timely access to the server