Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You really need to classify Java's Vector's type of thread safety. Javas Vector is safe to be used from multiple threads because it uses synchronization on the methods. State will not be corrupted. </p> <p>However, Java's vector's usefulness is limited from multiple threads without additional synchronization. For example, consider the simple act of reading an element from a vector</p> <pre><code>Vector vector = getVector(); if ( vector.size() &gt; 0 ) { object first = vector.get(0); } </code></pre> <p>This method will not corrupt the state of the vector, but it also is not correct. There is nothing stopping another thread from mutating the vector in between the if statement an the get() call. This code can and <strong>will</strong> eventually fail because of a race condition.</p> <p>This type of synchronization is only useful in a handfull of scenarios and it is certainly not cheap. You pay a noticable price for synchronization even if you don't use multiple threads. </p> <p>.Net chose not to pay this price by default for a scenario of only limited usefulness. Instead it chose to implement a lock free List. Authors are responsible for adding any synchronization. It's closer to C++'s model of "pay only for what you use" </p> <p>I recently wrote a couple of articles on the dangers of using collections with only internal synchronization such as Java's vector. </p> <ul> <li><a href="http://blogs.msdn.com/jaredpar/archive/2009/02/11/why-are-thread-safe-collections-so-hard.aspx" rel="noreferrer">Why are thread safe collections so hard?</a></li> <li><a href="http://blogs.msdn.com/jaredpar/archive/2009/02/16/a-more-usable-thread-safe-collection.aspx" rel="noreferrer">A more usable API for a mutable thread safe collection</a></li> </ul> <p>Reference Vector thread safety: <a href="http://www.ibm.com/developerworks/java/library/j-jtp09263.html" rel="noreferrer">http://www.ibm.com/developerworks/java/library/j-jtp09263.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload