Link Details

I have often read articles saying "If an object is immutable, it is thread safe". But I have never found an article that convinces me that 'immutable' means thread safety. Even the book by Brian Goetz Java Concurrency in Practice with its chapter on immutability did not fully satisfiy me. In this book we can read word for word, in a frame : Immutable objects are always thread-safe. I think this sentence deserves more explanation. So I am going to try to define immutability and its relation to thread safety.

Posted by mitchp  |   Oct 04 2012 / 11:40

Add your comment

Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.


User 379963 avatar

lacayo replied ago:

I don't get your point, the objects in your example are mutable: their state changes and because of that there can be problems if two threads use them at the same time.

Reply 0 votes
User 218789 avatar

eelmore replied ago:

Of course immutable objects are thread safe. A value cannot be changed if the value cannot be changed, duh.

Reply -1 votes

Recommended Links

Written by: Ryan Knight
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Play
  3. Akka
  4. Debugging JavaScript
  5. Design Patterns
  1. Apache Hadoop
  2. REST
  3. Java
  4. Git
  5. Java Performance
Connect with DZone