• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization

 
sach tend
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a class called A{} in which I have three methods.Inside one method I have given synchronized(A.class){ and some code here }.There are also other methods outside this class.I want to know whether the other two methods are also synchronized.I want to know this because I have given synchronized inside a method and if I call a method before entering into the synchronized method what happens ?

Thanks

Ljava
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

No other methods will be synchronized unless you use the "synchronized" keyword. If you use a synchronized block like this, then the method containing the block can start to execute, but the thread may be forced to wait before entering the block. Note that static synchronized methods of A will be synchronized on A.class, so if you have any static synchronized methods, they won't be able to execute at the same time as the synchronized block. Instance methods (non-static methods) synchronize on the current instance (i.e., "this") rather than A.class, so if you want to exclude non-static synchronized methods, then use "this" instead.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!