Question about EDU.oswego.cs.dl.util.concurrent.ReentrantLock
Hi there,
I can't use java-5's concurency classes because I still need to stay compatible to java-1.1, its a company descision ... I can't change it :-/
I've a network interface which basically consits of two operations:
1.) grabConnection
2.) releaseConnection
So when one thread grabbed the connection, all other threads have to wait in grabConnection, till the holding thread calls releaseConnection.
However its quite likely that the current thread will grab the connections more than once.
So this is what I did:
publicvoid grabConnection()
{
reentrantLock.acquire();
}
publicvoid releaseConnection()
{
if(reentrantLock.holds() > 0)
{
reentrantLock.release(reentrantLock.holds());
}else
{
System.out.println("Warning: RelaseConnection was colled although no one held the connection!");
}
}
The could should mean the following: As soon as the current thread calls releaseConnection all of its locks should be released.
However I ~sometimes~ get the warning message which should not happen as far as I understand.
Because each operation is forced to call grabConnection() first, and releaseConnection is always called after grabConnection no other thread should be able to call releaseConnection while the current thread holds the lock.
Any ideas whats wrong? Am I using the reentrant lock class the right way at all?
Thank you in advance, lg Clemens

