Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization

 
sunitha ravi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do we synchronize blocks of code without using threads? can we do that?
Sunitha
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunita,
What you specify can be done. However it comes at a cost where there is no benefit. An application that does not undertake concurrent access does not require synchronization. Only when threads come into the picture is the need for synchronization.
To cite an example. We have both the Vector and the ArrayList. Both do the same things. They store Objets and their sequence is preserved. However one of the fundamental differences is that the methods of the Vector are synchronized while that of the ArrayList are not. In a Single thread application you can use Arraylist as well as the Vector. However the use of Vector will create a overhead of synchronization.
In a multithreaded applicaton you still can use the methods of Arraylist and the Vector. But you have to explicitly synchronize access to the ArrayLIst
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!