Results 1 to 2 of 2
  1. #1
    ariak is offline Member
    Join Date
    Jul 2007
    Posts
    1
    Rep Power
    0

    Default Return in the Middle of synchronized Block

    Hi,

    What will happen if a code "return's" in the middle of synchronized block? Does it release a lock on the object that is holding or the lock would forever stay locked? i.e.

    synchronized (obj) {
    if(/* some condition */) {
    return;
    }

    }

  2. #2
    shanePreater is offline Member
    Join Date
    Jul 2007
    Location
    England, Bath
    Posts
    47
    Rep Power
    0

    Default

    It will release the mutex (obj) and return.

    You would probably be better off holding a boolean and then setting finished to true and only using return in a single place.

Similar Threads

  1. Programming block
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-25-2007, 12:20 PM
  2. synchronized
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-28-2007, 11:33 AM
  3. Middle Click Closes Tab Eclipse Plugin 1.0.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-20-2007, 06:59 PM
  4. doubt about synchronized
    By simon in forum Advanced Java
    Replies: 2
    Last Post: 08-05-2007, 04:49 AM
  5. Return to try block
    By Freddie in forum New To Java
    Replies: 2
    Last Post: 05-11-2007, 09:58 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
  •