Hi Prasun,
Here in the line
args.wait(12); the
thread that currently executes the line says it would like to give away the lock it has on the object "args"...
But to give away the lock the thread should have had the lock, rite?
Here it doesn't. This is synchronized on the ThreadDemo.class and not on the object "args" ==> implies it has taken the class's lock and not the args-object's lock.
So without even having the lock, how can you give it away? ==> Hence the IllegalMonitorException
To get the args-objects' lock, replace synchronized(ThreadDemo.class) with synchronized(args)
Regards,
Vishwa
[ January 18, 2008: Message edited by: Vishwanath Murthi ]