• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Synchronization

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Can any object call one Synchronized and one non-Syncronized method at a time.
method1() //Synchronized
method2() //non Synchronized

can any object like object1 call both method1 and method2 method at the same time.

Thanks,
Vivek
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Objects don't call methods. Threads call methods on objects.

Any number of threads can simultaneously execute unsynchronised methods on the same object.

Only one thread at a time can execute any synchronised method on the same object. Other threads have to wait.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mishra Vivek:
... Can any object call one Synchronized and one non-Syncronized method at a time.
method1() //Synchronized
method2() //non Synchronized
...


My understanding (please confirm/correct me) is that these aren't really called at the same time. The first method must return before the second is called.

But in any case, before a synchronized method can be executed, its object (or class) lock must be obtained by the calling thread.
[ February 15, 2005: Message edited by: marc weber ]
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic