Hi Ravish,
It seems we have got confused between the Main Thread as a normal Thread (which executes
the main method of
Java) and the Main daemon thread.
The Main daemon thread is the thread which I was refering to.The program Main thread is a
lightweight thread just like the newly spawn Thread.
To give an example, consider the following code :
You will see the output as
<pre>
I want to wait!!
Main Continues
</pre> However, you will still not see the prompt, which signifies the normal completion of the
program.This means the non-daemon Main thread had completed its execution,although the
daemon thread is still waiting for the newly spawn thread to complete its execution - hence
the daemon Main Thread waits infinitely for this thread to complete!
The use of join serves a different purpose.It signifies the non-daemon main thread to wait
for the completion of the newly spawn thread.
So if we have :
You will see the output as
<pre>
I want to wait!!
</pre> Note that "Main Continues" is never printed since the program main thread is waiting for
the newly spawn thread to complete!
In my earlier post, I had erroroneously mentioned that when we obtain a lock on the Object
(i.e. ref.wait()) we will have a normal termination of the program.The normal execution of
the program is only possible if the newly spawn thread is notified from its wait stage.
This is one of the possible ways to do it :
I believe my post is becoming rather too long!

Once we are together on this, we will look
into the difference between this.wait() and obj.wait()!BTW, I suggest you think of an
example by taking hints from my previous post on this.
HTH,
Sandeep
SCJP2, OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)