wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S Data => Lock-waiting giveup CPU Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S Data => Lock-waiting giveup CPU" Watch "B&S Data => Lock-waiting giveup CPU" New topic
Author

B&S Data => Lock-waiting giveup CPU

Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

when a 2nd threads tries to lock an "previously locked" record, do you guys think it is bad that it tries several time to "lock & wait" or that's not entirely "giving up CPU" ?

Below is an example:



Thanks
Alex
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
This situation occurs if all your threads are waiting only on one object - in your case it seems, that it is mutexRecords. Any thread, which unlocks any record causes all waiting threads to become alive (by using notifyAll()) and all threads must check status of record they are trying to lock. Other reason is spurious wake-up.

This approach should be OK, Andrew's book says, that per-record locking is probably not required.

Did you make this test with 2 threads only? Can you investigate reason why 2nd thread wakes up multiple times? I suggest to add thread name to any traces you make.
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

I understand the reason for this behavior (and designed it like that exactly).

I'm just wondering if a thread going back to "alive" state, just to go back to "wait" would count as "CPU usage".

The trace I pasted above were done when generating 100 threads, randomly accessing all records (with correct lock/unlock). To me, this is normal behavior, but I would be interested to know rancher's opinion on it (CPU usage).

Thanks
Alex
[ November 11, 2007: Message edited by: Alex Belisle Turcot ]
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
ok well I found other topics discussing that...

and I changed my code to synchronise/wait per record. And then only use notify, and the threads are no longer awaken just to call wait again.

I feel better with this approach.

Thanks
Alex
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S Data => Lock-waiting giveup CPU
 
Similar Threads
SCJD failed, help needed with locking!
CPU cicles in lock method
Record locking on recNo
Locking question
I passed, but I suffered the 44/80 locking penalty. Why?