File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can a synchronized and un-synchronized methods execute parallely

 
Nikita Dutt
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is possible.
 
seenu java
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you ; really enjoy being a part of java ranch
 
seenu java
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic