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

role of volatile and immutable

 
amitt jainn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the role of volatile and immutable types in multithreading ?

What I explored so far is a variable is volatile then it enforces a happen-before characteristic which insures no dirty reads of that variable whereas immutable types don't need synchronization.

I need help in exploring how and when of these definations ?

Thanks in Advance

Amit
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start Here
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Immutable objects are not something specific to multi-threading. Any object, the state of which can not be changed after they are created (to be precise it only means the internal state of object governed by the instance variables and not any references to the object itself) is called immutable.
Since, thread-safe code is something that *changes* modifies shared data in a way that even if the operations are inter-leaved, it never ever leaves the data in an inconsistent state, immutable objects do not require synchronization as they do not change.

Volatile is a weaker mode of synchronization and is effective in cases where no code follow a "check and act" semantics on the variable. Since JDK5, the AtomicXXX classes extends the concept of volatile variables to provide methods to atomically change variable values.

For more information you can follow the link Edward has pointed.
[ January 25, 2008: Message edited by: Nitesh Kant ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!