My assignment includes the following statement in its Locking requirement...
"Any attempt to lock a resource that is already locked should cause the current
thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available."
At first I took this to mean that I'd have to implement "wait()/notify()" everywhere that I "synchronized()" on the static Map containing my locked record info. However, I'm starting to question my assumption and think that "wait()/notify()" might not be necessary...
I have recently played around with deadlocking and have noticed that when I intentionally cause a deadlock to occur, the CPU cycles drop to 0%. It seems that both of my threads are waiting on the other to release there lock and while they are waiting they consume no CPU cycles.
Therefore, to keep things as simple as possible, I'm wondering whether I could avoid "wait()/notify()" entirely (at least in terms of locking) and just rely on "synchronized()" blocks of code to satisfy the requirement.
I've read MANY chapters on Threads & Locking, but still feel that my knowledge of when to apply "wait()/notify()/notifyAll()" is still lacking.
Any guidance is appreciated. Thanks in advance.