Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-06-2008, 08:30 AM
Member
 
Join Date: Oct 2008
Posts: 18
piyu.sha is on a distinguished road
[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
[
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-06-2008, 08:32 AM
Member
 
Join Date: Oct 2008
Location: US
Posts: 40
kzvi.kzvi.1 is on a distinguished road
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....

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-06-2008, 08:35 AM
Member
 
Join Date: Oct 2008
Posts: 45
priyanka.dandekar is on a distinguished road
A Non-Synchronized method can always be called without any problem.

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

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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 02:27 AM
public instance method steve123 New To Java 5 06-20-2008 10:45 PM
Calling a method for all instances of an object rattle New To Java 4 04-30-2008 04:10 PM
Instantiation using an instance factory method Java Tip Java Tips 0 03-29-2008 02:35 PM
Instantiation using an instance factory method JavaBean Java Tips 0 09-26-2007 10:25 PM


All times are GMT +3. The time now is 08:20 PM.


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