Abhinav : Let's take this one step at a time.
[With yield()] other threads ... get a chance to execute but at the same time it does not force
that thread to release the lock that it might have been holding. So what will be the use
of the yield() method when another thread wants to execute the same synchronized method,
since the lock has not yet been released?
1) As you said, yield() does not release an object lock. But there may not
be any lock to release. Remember that yield() can be used anywhere either
inside or outside of synchronized code.
2) Methods are not locked. It is objects that are locked. This means that in
a different thread, the same synchronized method can lock and operate on
a different object instance. And also in a different thread, non-synchronized
methods can operate on locked objects. This is why all access to a critical
object must be synchronized (locked) access.
3) So yield() allows the other threads to run. At some point one of them may
request the object lock held by the yielding thread, but this depends on the
software design and each thread's current state.
Jim ...
...