This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Synchronization  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?


author and iconoclast
Posts: 24203
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!