Distinguishing between READ and WRITE synchronized?

Example: highly multi-threaded application, but almost all threads use a common resource - read only in most cases.

In some rare cases (few in number and occurrence), however, the resource can be modified by a single thread. So the resource has to be synchronized, with the result that only one thread can be running at the same time.

Idea (stolen from data base systems...): Why not introduce something like a "weakSynchronized" in the Java standard, such that as many "weakSynchronized" blocks as there are can aquire the monitor on the resource at the same time without blocking each other. A normal "synchronized" then would have to work as follows: not allow any new "weadSynchronized" blocks to access the monitor (for not having to wait eternally), and then wait until all old "weakSynchronized" blocks release the resource.

What about this idea?

Background: Currently worked with such an application - decision was to use the good old synchronized for having easy code and not having to implement an own mechanism - but this way, the application is not as fast as it could be (was faster, but with deadlocks, when synchronization was not yet correct).

[1190 byte] By [Aconcaguaa] at [2007-11-27 7:39:03]
# 1
You mean like this: http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html
dannyyatesa at 2007-7-12 19:19:38 > top of Java-index,Core,Core APIs...
# 2
Seems so - obviuosly the java stuff had this idea just a little before me.Quite firm to java 1.4, but seems as if I still have to learn for 1.5...I'll have a look for that.
Aconcaguaa at 2007-7-12 19:19:38 > top of Java-index,Core,Core APIs...