Hi, I know there are a lot of locking questions already but anyway:
In my database class, I have several resources, such as the list of records, the list of reserved records and the random access file used to access the database binary file. At the moment I am controlling access to all of these using a single Reentrant lock. If I need access to any of these 3 resources, I use this one lock. I also have a single Condition that is used together with this lock. This simplifies the locking and makes it easier to track down deadlocking.
I just have one doubt: Would it be better to have a Reentrant lock for each of the 3 resources, and lock on all 3? This would make it clear which resources are being locked. - My only doubt is that 3 nested locks might not be necessary and might be bad style..
IMO it's advisable to use separate locks for each resource. No sense in having a thread block on a lock if it's being locked for a resource it's not even interested in. This is not bad form. Hope this helps.
SCJP 1.4 SCJD 1.5
Thanks tiny ad, for helping me escape the terrible comfort of this chair.