File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes where we have to synchronize???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "where we have to synchronize????" Watch "where we have to synchronize????" New topic
Author

where we have to synchronize????

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Mar 07, 2007
Posts: 1280

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

Joined: Jan 28, 2008
Posts: 5575

Thanks Marco
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41494
    
  53
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 ]

Ping & DNS - my free Android networking tools app
vinayak katkar
Greenhorn

Joined: May 28, 2008
Posts: 2
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


�Knowledge is the food of the soul.�<br /> <br /><br />To get free knowledge,ebook links, free pdf ,and new technology discussions visit the following link <br /><a href="http://vinayakkatkar.blog.co.in" target="_blank" rel="nofollow">http://vinayakkatkar.blog.co.in</a>
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks ULF and VINAYAK
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: where we have to synchronize????