I'm trying to convince myself that clojure is indeed easier than java for concurrency programming.
but I feel that the Clojure Refs/do-sync is almost exactly the same as java "synchronized" block. then I read this thread : Clojure STM ( dosync ) x Java synchronize block
--- I am restarting a new thread since if I comment there in the old thread, the response may not be high due to the old age.
the first comment in that thread by Michał Marczyk claims that the diff is that java sync block uses locks while Clojure uses transactions. I think this claim does not touch the essence of the problem: at the bottom, transactions are still implemented by locks. so "java using locks" is not the reason Clojure is better.
I think the real benefit is that Clojure transactions manages the locks automatically, just as DB transactions do. this way, the order to acquire locks, and the order to play transactions are determined by the transaction manager, so that programmer does not need to care about that, while in the java world, the programmer has to explicitly choose which lock to use for the sync block, which leads to possible deadlocks. transaction manager could use 2-phase locking for example to avoid deadlocks.
does the above make sense?
thanks Yang