Results 1 to 3 of 3
- 10-06-2008, 07:30 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 31
- Rep Power
- 0
[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]
- 10-06-2008, 07:32 AM #2
Member
- Join Date
- Oct 2008
- Location
- US
- Posts
- 58
- Rep Power
- 0
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 SeekerHave fun....
JAVA FAQs
- 10-06-2008, 07:35 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 68
- Rep Power
- 0
A Non-Synchronized method can always be called without any problem.
____________________________________________
Priya,
Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | DalCheers,
Eat Healthy Stay Fit
Similar Threads
-
[SOLVED] Can two threads call two different synchronized instance methods of an Objec
By piyu.sha in forum Threads and SynchronizationReplies: 3Last Post: 10-06-2008, 01:27 AM -
public instance method
By steve123 in forum New To JavaReplies: 5Last Post: 06-20-2008, 09:45 PM -
Calling a method for all instances of an object
By rattle in forum New To JavaReplies: 4Last Post: 04-30-2008, 03:10 PM -
Instantiation using an instance factory method
By Java Tip in forum Java TipReplies: 0Last Post: 03-29-2008, 01:35 PM -
Instantiation using an instance factory method
By JavaBean in forum Java TipReplies: 0Last Post: 09-26-2007, 09:25 PM
Bookmarks