wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Can a synchronized and un-synchronized methods execute parallely Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Can a synchronized and un-synchronized methods execute parallely" Watch "Can a synchronized and un-synchronized methods execute parallely" New topic
Author

Can a synchronized and un-synchronized methods execute parallely

Nikita Dutt
Greenhorn

Joined: Dec 24, 2010
Posts: 20
Hi all,


I am confused ; In a multiple threaded environment if a thread acquires a lock on instance ("this") of an object in a method. will an other thread can execute non synchronized methods on the same ("this") object.


Thanks in advance
Vladimir Ozerov
Greenhorn

Joined: Sep 27, 2011
Posts: 14
Yes, it is possible.
seenu java
Greenhorn

Joined: Oct 03, 2011
Posts: 12
the "lock" is associated with synchronized methods only,two synchronized methods cant run at a time,but non-synchronized methods can execute simultaneously.
Rajesh Nagaraju
Ranch Hand

Joined: Nov 27, 2003
Posts: 48
the "lock" is associated with synchronized methods only,two synchronized methods cant run at a time,but non-synchronized methods can execute simultaneously.


This need not be true always as it depends on the lock, if the lock is shared by two sycnhornized methods what you say is true.

If not they can run simultaneously.

Please correct me if I am wrong
Nikita Dutt
Greenhorn

Joined: Dec 24, 2010
Posts: 20
I agree with you rajesh , but i what i was looking ; for the same object can i have a synchronized and un synchronized methods being executed parallel y.
Rajesh Nagaraju
Ranch Hand

Joined: Nov 27, 2003
Posts: 48
Nikita Dutt wrote:I agree with you rajesh , but i what i was looking ; for the same object can i have a synchronized and un synchronized methods being executed parallel y.


THere is no need for a non-synchronized method to acquire a lock, it will be able to run parallely.
Nikita Dutt
Greenhorn

Joined: Dec 24, 2010
Posts: 20
Thanks to all of you ; really enjoy being a part of java ranch
seenu java
Greenhorn

Joined: Oct 03, 2011
Posts: 12
Hi Rajesh,
am not sure about the Shared lock and how it works,but two synchronized methods can be executed simultaneously when two different locks gets on two different synchornized methods(seperate locks),
could you please provide any links or information on shared locks.

http://download.oracle.com/javase/tutorial/essential/concurrency/locksync.html checks this might be useful
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can a synchronized and un-synchronized methods execute parallely
 
Similar Threads
synchonized method
ENLIGHTENING, thread synchronization, concept clarification --plz help
Synchronization
Synchronization
Lock for whole object? or only synchronized block?