Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-06-2008, 07:30 AM
Member
 
Join Date: Oct 2008
Posts: 31
Rep Power: 0
piyu.sha is on a distinguished road
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]
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-06-2008, 07:32 AM
Member
 
Join Date: Oct 2008
Location: US
Posts: 58
Rep Power: 0
kzvi.kzvi.1 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-06-2008, 07:35 AM
Member
 
Join Date: Oct 2008
Posts: 68
Rep Power: 0
priyanka.dandekar is on a distinguished road
Default
A Non-Synchronized method can always be called without any problem.

____________________________________________
Priya,
Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | Dal
__________________
Cheers,
Eat Healthy Stay Fit
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can two threads call two different synchronized instance methods of an Objec piyu.sha Threads and Synchronization 3 10-06-2008 01:27 AM
public instance method steve123 New To Java 5 06-20-2008 09:45 PM
Calling a method for all instances of an object rattle New To Java 4 04-30-2008 03:10 PM
Instantiation using an instance factory method Java Tip Java Tips 0 03-29-2008 01:35 PM
Instantiation using an instance factory method JavaBean Java Tips 0 09-26-2007 09:25 PM


All times are GMT +2. The time now is 11:37 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org