Writable lock nested in read-only lock
Brian Smith <[email protected]> Mon, 30 Sep 2002 03:23:53 -0500
| Newsgroups | gmane.comp.java.netbeans.modules.mdr.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I am writing some code like this:
repository.beginTrans(false);
try {
// [1] read only part
boolean ok = false;
if (I need to write to the repository then) {
repository.beginTrans(true);
try {
// [2] read-write part
ok = true;
} finally {
repository.endTrans(!ok);
}
}
// [3] read only part
} finally {
repository.endTrans();
}
As you can see, I have a write transaction nested inside of a read
transaction. The reason I am doing this is because I want to lock the
repository against _writes_ for all three parts, [1], [2], [3], but I
want to lock the repository against _reads_ for as little time as
possible [2]. However, MDR responds with an error: Writable lock nested
in read-only lock.
Would it be possible to change MDR's behavior so that writable locks
could be nested inside read-only locks? Is this an unsound thing to do?
It seems sound to me (the inner call to beginTrans() would block until
all _other_ readers ended their transactions, just like any other call
to beginTrans(true)). Is there a better way to do what I want?
Thanks,
Brian