Using "synchronized" but still getting IllegalMonitorStateException
Hi,
I'm trying to execute this bit of JUnit test code (Java 1.5):
public void testEventLoggerFailure() {
try {
synchronized(this) {
EventLogger el = new EventLogger(null,
null,
null,
null);
el.start();
el.wait();
} // synchronized
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} // catch
} // testEventLoggerFailure
but yet, at the "el.wait()" line the below exceptioin is thrown ...
java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:474)
at ConnectionErrorsTest.testEventLoggerFailure
(ConnectionErrorsTest.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run
(JUnitTestRunner.java:297)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch
(JUnitTestRunner.java:672)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main
(JUnitTestRunner.java:567)
Any ideas? Thanks, - Dave