Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where we have to synchronize????

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

in program,where we need to synchronize?

in which scenario syncronization is need?

i study some tutorial,still i confused..

please anyone can explain me with real time example..

Thanks & Regards,
seetharaman.v
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi seetharaman,

in short you need synchronization when using multiple threads in an application. Synchronization is needed to prevent unexpected access to shared data among multiple threads. Without proper synchronization you have good chances for corrupted data and kind of non-deterministic behavior of your program.

But multi-threading and correct synchronization is really a complex topic and you should search for tutorials or documentation on it. Unfortunately it's simply not possible to explain this here in a few sentences.

Marco
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marco
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While Marco's answer is spot on, I'd like to add one little detail.

Specifically, you need to synchronize if you have shared mutable data. If the data that's shared between threads is immutable -meaning it does not change during it's lifetime, or if you can guarantee that it does not change when there's a chance of concurrent access- then there's no need for synchronization.
[ May 28, 2008: Message edited by: Ulf Dittmer ]
 
vinayak katkar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronize key word is used with methods or block of code in methods
It is used where the block of code is sharing common resources
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ULF and VINAYAK
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic