Shivit,
without trying to debug the above example ... here is how notify() works.
Notify() is a method of class object that informs one
thread and one thread only (notifyAll() informs all waiting threads) that it can stop waiting and continue with program execution.
For example: thread A acquires the lock [aka 'monitor'] on object Foo which is running in thread B. Thread A calls the wait method() of the Foo instance and releases its lock. This tells Foo instance .. I'm gonna wait until you notify me that you are finished whatever it it is you are doing. Foo instance finishes and calls notify(). Thread A goes back to runnable, reaquires the lock on foo instance and will complete.
Both wait and notify must be called from a synchronized method (or block). Wait throws an InterruptedException.
hope this helps.