Hi all,
Im using ReentrantLock, to implement a Semaphore, for an assignment, i have implemented that for a certain level, but have some issues.
Hope anybody of you can help me on this.
My intention is to have 2 threads, 1
thread prints value 0, and the other prints 1, and i need to have those values print in order..
first prints
0, and then
1
But im getting the following exception
Thread number is : 0
waiting...
Exception in thread "Thread-1" java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:485)
at org.concurrent.saj.Semaphore.p(Semaphore.java:29)
at org.concurrent.saj.MyThread.run(MyThread.java:29)
at java.lang.Thread.run(Unknown Source)
What i doubt was, the place where i invoke wait( ) is not a synchronized code block. Isn't it enough to invoke lock.lock( ) to make that code synchronized, ??
or else do i need to follow some other approach with this ReentrantLock ??
your qiuck response is highly appreciated.
Thanks in advance
saj
code snippets are listed below.