Rajendra Prakash wrote:Hi Friends, I am beginner in java. what i know about synchonized keyword is,If more that one 1 thread tries to access a particular resource we can lock the method using synchronized keyword.
When you have a synchronized method (or block), only one thread is allowed to execute that method (or block) at any given time.
Then after that how the lock is released and how next thread access that.
Lock is released whenever the thread is done with it (method in this case), so the JVM can assign another thread waiting for that lock.
Also explain object level lock and method level lock.
I haven't heard of "object level lock" (may be it's referring object lock ?)
However there are two types of locks (monitors) in Java. Object lock & Class lock, those can be aquired by a thread. Class lock is per class basis & object lock is per object. If you have synchronized instance method(s) (or block), a thread wish to execute that method should aquire the lock for that particular object. Class lock is associated with the class. So any synchronized static method would need the class lock to be aquired by the thread which wish to execute that method. There are lot more to this but I suggest you go through
Concurrency tutorial by Sun. And please
CarefullyChooseOneForum when posting.