Java Threads, Oaks

D

dmcreyno

Has anyone written a unit test for ConditionVariable (from "Java
Threads").

I am trying to write a Junit test for ConditionVariable.java from
Scott Oaks' 'Java Threads' book (the one with the top on the cover). I
keep getting a exception thrown by ConditionVariable

55:07,515 ERROR [Writer]
org.dlm.util.sync.ConditionVariable.cvTimedWait(ConditionVariable.java:113)
cvTimedWait() - owner: null current: Writer
java.lang.IllegalMonitorStateException: current thread not owner
at org.dlm.util.sync.ConditionVariable.cvTimedWait(ConditionVariable.java:118)
at org.dlm.util.sync.ConditionVariable.cvWait(ConditionVariable.java:73)
at org.dlm.test.Writer.send(Writer.java:53)
at org.dlm.test.Writer.run(Writer.java:48)

As we can see, if printed the results of getBusyFlagOwner and it is
null.

Thread theOwner = sv.getBusyFlagOwner();
Thread current = Thread.currentThread();
if ((theOwner != current)) {
log.error(
"owner: "
+ sv.getBusyFlagOwner()
+ " current: "
+ Thread.currentThread().getName(),
new IllegalMonitorStateException("current thread not owner"));
System.exit(-1);
//throw new IllegalMonitorStateException("current thread not
owner");
}


Well, of course its null. No one has the lock - the getBusyFlag()
method has never been called.

http://www.mycgiserver/~dlm8751/ConditionVariable.java
http://www.mycgiserver/~dlm8751/ConditionVarTestCase.java
http://www.mycgiserver/~dlm8751/Reader.java
http://www.mycgiserver/~dlm8751/Writer.java
http://www.mycgiserver/~dlm8751/BusyFlag.java
http://www.mycgiserver/~dlm8751/log.txt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top