Name: joT67522 Date: 09/04/97
The problem is that I do not want to access an object if it
is locked by another thread executing code inside a
synchronized block. But there is no way to know if an object
is locked without using some home grown method. My current
method for reducing the locks in the system is by cloning
my dataobjects when I want to (for example) write them to
a file. I am sure I am not the only one encountering similar
problems.
Since synchronized is a language feature I suppose it would
be preferable to add this to the language.
synchronizedNOWAIT(object) {
.
.
.
}
If the object is locked an exception (ObjectIsLockedException?)
would be thrown. I know this looks ugly, but you get the general
idea. Throwing an exception is not very pretty either but having
an alternate block to execute would be even uglier.
Maybe a queriable LockManager:
if(LockManager.lockIfNotLocked(object))
.
.
.
else
.
.
.
This would give the user the responsibility of unlocking
the object which could lead to undesireable effects and
advanced debugging.
Another idea: a Lock object (this could be easily built if
we had a LockManager)
Lock lock = new Lock(object);
if(lock.locked())
...
else
...
The garbage collector would then take care of removing locks,
which is a bit better than the previous but still not good
enough.
company - MSC Konsult , email - ###@###.###
======================================================================