Developed interest after attending "Concurrency without pain in pure java" session by Venkat Subramaniam
If i am not sure about your question, i will go back do my research and will get back to you.
Bank Account System
Lets use the java 'synchronization' and develop a bank account system
Problems with Java Synchronization
No errors/warning from JDK
Programmers can get synchronization wrong
Too conservative - Back to single threaded execution
Thread Contention - waiting for lock
Deadlock - Waiting infinitely for locks
Conflating Identity with State
Conflating Identity with State
When we create an object (Employee) in java
we receive a pointer to the instance that serves as both
its identity - Object represents Palanivel , Employee
State - Object also hold info about my start data July 2006
Anyone having access to the object can change the start date
Previous start date is lost forever
A thread with a pointer to Employee Palanivel has to assume that its value can change at any moment - So we add 'synchronization'
Software TRANSACTIONal Memory
Identity and state are managed separately
Identity - a stable logical entity associated with a series of different values over time
value - something that doesn't change. All values are immutable
The date May 03, 1985 never change
You might have an identity called “today”
At one point, “today” was associated with “May 03, 1985”
The next day, it was associated with “May 04, 1985” and now that identity is associated with “Dec 02, 2013”
STM
The identity is ALWAYS associated with a single immutable value at a given time; someone (a thread) can request that it be associated with a different immutable value (perhaps creating the new value based on the old value)
the association is then changed, not the values
This immutability is good in concurrent situations, since there is never any danger of a value changing out from under you
STM
STM BENEFITS
separating identity from state
lock-free programming
Keep tracks of mutable identity and screams if its modified outside of a transaction
Multiple threads can read this value with no contention
clojure
Clojure is a dynamic programming language
Implements STM
Can be used in Java apps by including the library to classpath