I'm trying to create a fine grain locking mechanism for the following scenario:
I have a data store with many serialised
objects inside it. Each
belongs to a certain person, group or company and each
can be modified in one of four ways: they can be created, deleted, removed from or inserted into. While a
is being modified I want to block access to it. Each
is identified using a
object which stores the directory and file name as well as the full path for convenience.
Currently I am using an array list inside a class called
which holds current
objects being processed. Then when another thread comes in it checks the queue to see if the
it is requesting is already being used. If this is the case a while loop is used to keep checking the
periodically until the request that put it there removes it.
I was thinking it might be an idea to have a HashMap of
values. This would result in a large set of
objects but I could manage the queue fairly well.
Is there a better way to do this sort of fine grain locking?