Results 1 to 4 of 4
  1. #1
    piyu.sha is offline Member
    Join Date
    Oct 2008
    Posts
    31
    Rep Power
    0

    Question [SOLVED] Can two threads call two different synchronized instance methods of an Objec

    Can two threads call two different synchronized instance methods of an Object?

    I am still not sure on this, If I have two different methods in a object and two different threads are calling them.....is it possible?

    Not sure if I understood the question right.... but looks like really fundamental question. Please provide your suggestions and pointers...
    Live life king size
    [Lucene]

  2. #2
    kzvi.kzvi.1 is offline Member
    Join Date
    Oct 2008
    Location
    US
    Posts
    58
    Rep Power
    0

    Default

    No. If a object has synchronized instance methods then the Object itself is used a lock object for controlling the synchronization. Therefore all other instance methods need to wait until previous method call is completed.
    See Sample Code which demonstrate it very clearly.

    ____________________________________________
    Software Wiki | Interview FAQs | Lucene Search | Oracle | ORM | Struts2 | Job Seeker
    Have fun....
    JAVA FAQs

  3. #3
    Join Date
    Oct 2008
    Posts
    68
    Rep Power
    0

    Default

    Try out some code yourself, it should be more easier. Also it will be memorized. You can try more combination on same multi threaded applications.

    ____________________________________________
    Priya,
    Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | Dal

  4. #4
    Join Date
    Oct 2008
    Posts
    68
    Rep Power
    0

    Default

    Btw just to answer your question,
    You cannot call two synchronized methods of a class on the same object. This is the use of synchronization. If you can call two synchronized methods on the same object then there is a chance of corruption of the state of the object. Synchronization helps you to avoid this....

    ____________________________________________
    Priya,
    Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | Dal

Similar Threads

  1. accessing instance variables from static methods
    By ravian in forum New To Java
    Replies: 7
    Last Post: 03-01-2009, 10:09 PM
  2. How to call methods of different classes
    By adeeb in forum New To Java
    Replies: 2
    Last Post: 06-06-2008, 06:08 AM
  3. How to synchronize threads on an object
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:39 PM
  4. Replies: 0
    Last Post: 01-02-2008, 01:52 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
  •