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

[1957 byte] By [linuxhippya] at [2007-10-2 23:11:07]
# 1
It should be noted that SUN has EOL 1.1, 1.2 and 1.3With the upcoming release of 1.6, version 1.4 days will be numbered.Sun supports some very large companies, but your company wants to support versions even they don't support.
Peter__Lawreya at 2007-7-14 6:25:11 > top of Java-index,Core,Core APIs...
# 2

> Sun supports some very large companies, but your

> company wants to support versions even they don't

> support.

Well Java-1.3 is still installed on all BMW clients (yes the car manufacturer) by default.

That is reality and our most important customer so ... I have to support.

After all do you really think anybody would leave the auto-update feature on *rofl* ... ending up with 15 different versions of java on his computer eating up several gigs and beeing nerved with this lousy popup all the time.

Forget about it, noone will do :-/

But back to my original question, would you be so kind to help me?

lg Clemens

linuxhippya at 2007-7-14 6:25:11 > top of Java-index,Core,Core APIs...
# 3

For questions on Doug Lea's package I suggest asking Doug Lea :)

See http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest for all things related to the design, use and ongoing development of java.util.concurrent and concurrent programming in Java in general, as well as Doug's older stuff on which j.u.c is based.

Also there is a backport of j.u.c that may be of assistance. It might be easier to get it to work with even older JDK versions

davidholmesa at 2007-7-14 6:25:11 > top of Java-index,Core,Core APIs...