Set - 7

Question 31 :

Why do threads block on I/O?

Answer :

Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o Operation is performed.


Question 32 :

What is synchronization and why is it important?

Answer :

With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors.


Question 33 :

Is null a keyword?

Answer :

The null value is not a keyword.


Question 34 :

Which characters may be used as the second character of an identifier,but not as the first character of an identifier?

Answer :

The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.


Question 35 :

What is the difference between notify() and notifyAll()?

Answer :

notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a "writer" lock on a file might permit all "readers" to resume).