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.
Monday, October 6, 2008
Can a thread call a non-synchronized instance method of an Object when a synchronized
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?
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?
Subscribe to:
Posts (Atom)