• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Synchronization

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Threads and Synchronization...
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic