Originally posted by dolly shah:
Hi Chandra,
I am little confuse about (this) means current instance. And here current instance is boolean. So how synchronized can take lock of (this)?
Can you explained?
Thanks.
Nay Dolly, boolean is not current instance.
See the following points regarding your class:
1- "A" is a class, every instance of your class 'A' will contain a variable
done. "done" is an instance variable.
2- "a1" is a thread object.
3- You are simply acquiring lock of the thread object 'A' before entering
to the sync code.
4- Any code that writes "this" inside the code of your class (non-static),
it will refer to current object. Suppose you call a1.method() and
inside method() you say "this", it means you are referring to the object
using the ref variable you have called the method.
Note: Try to implement the full code, that demonstrate the use of "done",
to exit from the waiting loop. It may help you to understand the things
in much better way;
Thanks,