[concurrency-interest] Creating custom locks

Luís Eduardo V. Matta levmatta@uol.com.br
Wed, 19 Nov 2003 22:42:09 -0200


This is a multi-part message in MIME format.

------=_NextPart_000_000F_01C3AEEE.5DF98930
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Some weeks ago,
     "we" had a discution (the second time around) about LockManagers =
and owned Locks, even though I agree that it its not the place neither =
the time for this I would like to make some requests. My objective is to =
make the subject and implementation more reachable (especialy to me).

As far as I can tell LockSupport is fairly low level enough to implement =
any kind of lock: (fair , priority, fair with prioraty, with prioraty =
invertion, reentrant or not, owned and etc, that permit threads messing =
with locks that it doesn't own). Is this true? Does anybody disagree?

But the lock classes aren't vary user freindly. Please change this, if =
security is a concern then create a level of abstract classes and make =
the others final. Example:=20

public class ReentrantLock implements Lock, java.io.Serializable {
... other stuff

    final void checkOwner(Thread t) { //why final
        if (owner !=3D t)=20
            throw new IllegalMonitorStateException();
    }
}

Extending ReentrantLock or ReentrantReadWriteLock is a very good =
implementation decision to anyone with special needs, so I believe this =
will be well recieved.

Thanks,
Lu=EDs Matta
------=_NextPart_000_000F_01C3AEEE.5DF98930
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1276" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Some weeks ago,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;"we" had a =
discution (the=20
second time around) about LockManagers and owned Locks, even though I =
agree that=20
it its not the place neither the time for this I would like to make some =

requests. My objective is to make the subject and implementation more =
reachable=20
(especialy to me).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>As far as I can tell LockSupport is =
fairly low=20
level enough to implement any kind of lock: (fair , priority, fair with=20
prioraty, with prioraty invertion, reentrant or not, owned and etc, that =

permit&nbsp;threads messing with locks that it doesn't own). Is this =
true? Does=20
anybody disagree?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But the lock classes aren't vary user =
freindly.=20
Please change this, if security is a concern then create a level of =
abstract=20
classes and make the others final. Example: </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>public class ReentrantLock implements =
Lock,=20
java.io.Serializable {</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>... other stuff</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; final void =
checkOwner(Thread t)=20
{ //why final<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (owner =
!=3D t)=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
throw new=20
IllegalMonitorStateException();<BR>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Extending ReentrantLock or =
ReentrantReadWriteLock=20
is a very good implementation decision to anyone with special needs, so =
I=20
believe this will be well recieved.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Lu=EDs Matta</FONT></DIV></BODY></HTML>

------=_NextPart_000_000F_01C3AEEE.5DF98930--