• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Synchronization  RSS feed

 
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
 
author and iconoclast
Sheriff
Posts: 24220
40
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!