aspose file tools*
The moose likes Threads and Synchronization and the fly likes Synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Synchronization" Watch "Synchronization" New topic
Author

Synchronization

Kannan BLR
Greenhorn

Joined: Mar 01, 2005
Posts: 10
Hi All,

Please Any one help me what is Synchronization?
Why iam asking this one ? I got the answer from this question (diff. between Vector and Arraylist).

Vector is syncronized.
Arraylist is not syncronized.


Kannan.A<br />kannanmsc@sify.com
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, welcome to the ranch!

Synchronization is used in multi-threaded programs to make sure that only one thread gets into a sensitive code block at a time. If I have code that might be run by two threads and it does something as simple as:

it is possible for another thread to change the value of memberVariable between the time I set it and the time I test it and the method might not print YES. If I make the method synchronized, the compiler adds code to guarantee that only one thread gets into this method at a time, and the method will always print YES.

This is a silly example, but real apps often have resources that are shared by many threads yet have to be modified by only one at a time.

See if Thinking in Java or this Sun Tutorial help you get into threading. The ranch has a forum just up the page all about threading if you want to take future questions there.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Moving to Threads and Synchronization...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronization