• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can a synchronized and un-synchronized methods execute parallely

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it is possible.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all of you ; really enjoy being a part of java ranch
 
seenu java
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic