hi,
i think, this code will throw java.lang.IllegalMonitorStateException: not IllegalStateException ...
see, there are two things thread of execution and thread object having 1-1 mapping.
A thread object is just like other java objects so it also has a lock and any thread can acquire it.but remember, a thread of execution never hold the lock of its thread object but it can acquire by calling synchronized block or method.
that is the reason sometimes, run() is made synchronized.
so in the above code,
the current thread (means,thread of execution) will try to acquire the lock of
current thread (here, it is thread object) which is available. so no,
IllegalStateException.
but in the synchronized block you are calling wait on obj object whose lock is not acquired by thread(thread of execution) and throws IllegalMonitorStateException.
Am i right?
regards,
Vikram
preparing for scjp1.5