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

    Question [SOLVED] Non-synchronized instance method of an Object

    Can a thread call a non-synchronized instance method of an Object when a synchronized method is being executed ?

    I am having difficulty understanding this synchronization stuff.

    Assume if a Class has two methods
    - method1 is synchronized instance method
    - method2 is a regualr instance method

    So in this scenario, can there be two threads calling these two methods in parallel for the same instance?
    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

    Looks like you are having problem understanding the core fundamental of synchronization. You should start writing code for testing all these scenarios.

    To answer your question.

    Yes, a Non synchronized method can always be called without any problem. In fact Java does not do any check for a non-synchronized method. The Lock object check is performed only for synchronized methods/blocks. In case the method is not declared synchronized Jave will call even if you are playing with shared data. So you have to be careful while doing such thing. The decision of declaring a method as synchronized has to be based on critical section access. If your method does not access a critical section (shared resource or data structure) it need not be declared synchronized.

    See the Example Code which demonstrate the same.

    ____________________________________________
    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

    A Non-Synchronized method can always be called without any problem.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-06-2008, 12:27 AM
  2. public instance method
    By steve123 in forum New To Java
    Replies: 5
    Last Post: 06-20-2008, 08:45 PM
  3. Calling a method for all instances of an object
    By rattle in forum New To Java
    Replies: 4
    Last Post: 04-30-2008, 02:10 PM
  4. Instantiation using an instance factory method
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-29-2008, 12:35 PM
  5. Instantiation using an instance factory method
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 08:25 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
  •