Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

synchronized

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i m TahaAlimy question is that what is synchronized..
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Taha, I'm going to move this post to the Java Beginners forum where it can be properly answered.
Also, you may want to do a search on that forum for the word "synchronized", I'm sure you'll find many posts.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Taha,
Welcome to JavaRanch. Java is a multi-threaded language, which means that in a single application you can have many threads of execution running at the same time. Let's say you have a class which has a reference to some object which can be changed when certain methods are called. What do you think would happen to that object if five threads were allowed to gain access to it at the same time? It would soon become corrupted. That is where synchronized comes in. Using the synchronized keyword on a method or an object guarantees that only one thread at a time can gain access to that block of code. Here are a couple of examples:
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic