• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronization

 
Saurabh Saha
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • 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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic