This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread safe

 
Blanka Li
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Vector and HashTable are the only classes that are thread-safe".
what is the meaning of "thread-safe" here? And why the two class are thread-safe?
thanks!
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Blanka, wellcome to the Ranch
Thread safe means that it is safe for several threads call the methods of an object, because they are not going to be executed simultaneously. Imagine wanting to add an element at the same time an iterator is returned, or deleting other.
Because the code in the methods of Vector and HashTable are synchonized. One thread would have to wait before entering a method that is "protected" (synchronized on) by the same lock that has been adquired by another thread.
Read more on the Java Tutorial , and this Thinking in Java's chapter
 
Blanka Li
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose Botella, thank you very very much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic