• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization

 
Raghuram Kristipati
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one please let me know when can we use synchronization with a example. I am in a great confusion regarding this thing.
 
Henry Wong
author
Sheriff
Posts: 22518
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raghuram Kristipati:
Can any one please let me know when can we use synchronization with a example. I am in a great confusion regarding this thing.


Synchronization is *not* just some API that you use for a particular service, you really need to understand what you are doing.

Take a look at the Sun Threads Tutorial to start.

Henry
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Raghuram, welcome to the ranch! That tutorial is definitely the place to go. Since you asked about synchronization (just one part of threading) I'll venture a very short explanation.

Often when two threads share a resource it is necessary to make sure only one thread accesses it at a time. A resource can be any object or something outside the JVM. For example, a "race condition" is A Bad Thing that happens if I set a value on an object and some other thread changes it before I get around to using it. Synchronization is mostly about making the threads access something one at a time.

Note that in the tutorial synchronization is a ways down the page. You can do a lot of threading without having two threads share any resources so there's plenty to learn before synchronization.

Have fun! Ask more questions as you go!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!