Results 1 to 5 of 5
  1. #1
    Gobi is offline Member
    Join Date
    Jun 2011
    Posts
    13
    Rep Power
    0

    Default Query abt Synchronised ??

    Hi All,
    I want to know something abt synchronized.
    Java Code:
    class A {
    
    // time consuming function 
    public synchronized void fn1(){
    ...
    ...
    
    
    ...
    
    }
    
    // it simply adds two numbers and return it.
    
    public int fn2(){
    return 5+3;
    }
    
    }
    now , I have two threads say T1 and T2.

    T1 is calling fn1() , and doing some operation and it got timed out in between.
    Now, T2 calling fn2() of the same object.

    here my question is ,
    1.when T1 calling fn1() , what does happen internally?where the lock will create?
    2.what will happen while T2 calling fn2() of the same object.
    3. what are the advantage of sync mtd over sync block?


    Thanks in advance.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    when T1 calling fn1() , what does happen internally?where the lock will create?
    The lock will be on the object containing the fn1() method.

    2.what will happen while T2 calling fn2() of the same object.
    The method should execute with no problem.

    what are the advantage of sync mtd over sync block?
    The block has smaller scope.

  3. #3
    Gobi is offline Member
    Join Date
    Jun 2011
    Posts
    13
    Rep Power
    0

    Default

    Hi,
    Thanks for your reply...
    But still i need more info from you

    The lock will be on the object containing the fn1() method
    U mean to say , a byte memory will be added in the object to hold d lock?
    then this might be kind of locking d object , if i'm right

    I would really appreciate you , if u have shared any pictorial representation abt sync concept

    Thanks in advance!!!

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    a byte memory will be added in the object to hold d lock?
    How the lock is implemented is not important to using it. And it can be implemented differently on different OSs.

    any pictorial representation abt sync concept
    Google is the way to go for more info.

  5. #5
    Gobi is offline Member
    Join Date
    Jun 2011
    Posts
    13
    Rep Power
    0

Similar Threads

  1. need sql query
    By murali23krishna in forum JDBC
    Replies: 8
    Last Post: 05-17-2011, 11:42 AM
  2. hql query
    By murali23krishna in forum JDBC
    Replies: 1
    Last Post: 03-17-2011, 07:25 AM
  3. I need help with a query.
    By Daredemo in forum JDBC
    Replies: 1
    Last Post: 08-13-2008, 05:16 AM
  4. Using sql:query tag
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-15-2008, 03:13 PM
  5. Using sql:query tag
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-14-2008, 09:31 AM

Tags for this Thread

Posting Permissions

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