Results 1 to 3 of 3
  1. #1
    Ash-infinity is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default calling yield() method in synchronized block

    Hi everybody ,
    when a yield() method is called in a synchronized block does that thread releases the lock???

    or it just holding the lock and going to the ready state???

    please any one explain me


  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Rep Power


    No. Calling yield() relinquishes the CPU but, like sleep(), holds on to any synchronization locks. This is different to wait(), which does relinquish the lock on the object being waited on (but only that object).

    I've written up some more detailed information on what Thread.yield() does on different systems/VM versions in case you're interested.

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Zurich, Switzerland
    Rep Power

    Default Re: calling yield() method in synchronized block

    Thread has a state RUNNABLE that means that this thread is eligible from the scheduler to run and change the state from RUNNABLE to RUNNING. Using yield() on a thread the thread change his state from RUNNING to RUNNABLE. But if all threads has the same priority the same thread my return to the RUNNING state so that yield() has no effect at all.

Similar Threads

  1. [SOLVED] Non-synchronized instance method of an Object
    By piyu.sha in forum Threads and Synchronization
    Replies: 2
    Last Post: 10-06-2008, 06:35 AM
  2. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  3. method calling?
    By frejon26 in forum New To Java
    Replies: 4
    Last Post: 01-25-2008, 03:38 AM
  4. Return in the Middle of synchronized Block
    By ariak in forum Advanced Java
    Replies: 1
    Last Post: 07-26-2007, 10:24 AM
  5. Help with Calling a method
    By Albert in forum New To Java
    Replies: 3
    Last Post: 07-10-2007, 03:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts