[Ajay]: what will happen if notify() is called before starting the thread?
Nothing. That is, you can call notify(), and the method will execute almost immediately, with no effect. Any time you notify() something that's not in a wait(), the notify() is simply ignored. You can observe this yourself by writing a simple test. [ May 31, 2006: Message edited by: Jim Yingst ]
Originally posted by Edward Harned: Can you do that, NO.
Will it work, NO.
start() does more than execute the run() method.
Wrong. It will work perfectly fine, it just won't have any useful effect because in that code at no point is any thread in the wait set of t. You seem to be making the same error the OP is, that is in thinking that wait() and notify() have anything to do with Thread or anything to do with start().
wait() and notify() are a synchronization aid that can be invoked on any Object. When wait() is invoked on an Object the current thread of execution is suspended and that thread is added to the Object's wait set. The thread will resume when it is either removed from that wait set or when it is interrupted. Invoking notify() on an Object will remove one thread from it's wait set, invoking notifyAll() will remove all threads from it's wait set.
In your code example your are invoking notify() on "t". That t is a Thread is not relevent and the state of t is also not relevent. All that happens is that you acquire the monitor for t (or rather the object pointed to by the reference variable t) and then invoke notify() on t which removes all threads from it's wait set. However, at that point it is impossible for any thread to be in t's wait set because you just created it and you have not invoked wait() on it from any thread, so it will do nothing.