Discuss each of the following terms in the context of Java’s threading mechanisms:
a) synchronized
b) wait
c) notify
d) notifyAll
e) Lock
f) Condition
a) When a method or block is declared synchronized and it is running, the object is locked. Other threads cannot access the other synchronized methods of the object until the lock is released.
b) Places a thread in the waiting state until another thread calls notify or notifyAll on the same object or until a specified amount of time elapses.
c) Wake a thread currently waiting on the given object.
d) Wake all threads waiting on the given object.
e) An interface implemented by objects that control access to a resource shared among multiple threads. Only one thread can be holding a Lock at one time—a second
thread calling the lock method will block until the unlock method is called. Using
the Lock interface is more complicated than using the synchronized keyword, but is more flexible.
f) Objects of this interface represent condition variables that can be used with Locks to manage access to a shared resource.
You might also like to view...
What is the range of legal values for an array of size n?
What will be an ideal response?
In a ____ queue, customers or jobs with higher priorities are pushed to the front of the queue.
A. structured B. divided C. priority D. hold
What is the oldest of the TCP/IP symmetric-key algorithms?
A. Data Encryption Standard (DES) B. Advanced Encryption Standard (AES) C. Rivest Cipher 4(RC4) D. public-key cryptography
Write the code segment that inserts a new node to which newPtr points at the beginning of a linear linked list.
What will be an ideal response?