The concepts, as well as the Clojure implementation, presented in this
article, may be useful for those designing and implementing some of the
"distributed wiki" and "load-balancing" capabilities of 2.X; also for
"realtime group editing" features I've seen mentioned in the survey. Also,
the concepts here could help in designing finer-grained, yet
"federalized/distributed" locking for concurrent access e.g. which might be
needed for "collaborative" or simultaneous editing of xwiki documents, as
well as load-balanced wikis. This also isn't just "starry eyed theory" --
via JSR223, these features could be integrated into the Xwiki Java API,
giving a "concurrent scripting face" to the Xwiki API running on multiple
wiki hosts. (see
http://groups.google.com/group/clojure/msg/ad811b69d448e3db re
JSR-223 status of Clojure).
Software Transactional Memory <http://java.ociweb.com/mark/stm/article.html>
- Overview <http://java.ociweb.com/mark/stm/article.html#Overview>
- Lock-based
Concurrency<http://java.ociweb.com/mark/stm/article.html#Locks>
- Actor-based
Concurrency<http://java.ociweb.com/mark/stm/article.html#Actors>
- Transactional Memory <http://java.ociweb.com/mark/stm/article.html#TM>
- Software Transactional
Memory<http://java.ociweb.com/mark/stm/article.html#STM>
(STM)
- Persistent Data
Structures<http://java.ociweb.com/mark/stm/article.html#PersistentDataSt…
- STM
Implementations<http://java.ociweb.com/mark/stm/article.html#STMImplemen…
- Clojure
Overview<http://java.ociweb.com/mark/stm/article.html#ClojureOverview>
- Clojure Reference
Types<http://java.ociweb.com/mark/stm/article.html#ClojureReferenceTypes…
- Clojure Validators and
Watchers<http://java.ociweb.com/mark/stm/article.html#ClojureValidatorsA…
- Clojure STM - High
Level<http://java.ociweb.com/mark/stm/article.html#ClojureSTMHigh>
- Clojure STM - Low
Level<http://java.ociweb.com/mark/stm/article.html#ClojureSTMLow>
- Conclusion <http://java.ociweb.com/mark/stm/article.html#Conclusion>
- References <http://java.ociweb.com/mark/stm/article.html#References>
Clojure has built-in support for Concurrency:
(
http://java.ociweb.com/mark/clojure/article.html#Concurrency )
Managing concurrency with locks is hard. It requires
determining which
objects need to be locked and when they need to be locked. These decisions
need to be reevaluated when the code is modified or new code is added. If a
developer forgets to lock objects that need to be locked or locks them at
the wrong times, bad things can happen. These include
deadlocks<http://en.wikipedia.org/wiki/Deadlock>
and race conditions <http://en.wikipedia.org/wiki/Race_condition>. If
objects are locked unnecessarily, there is a performance penalty.
Support for concurrency is one of the main reasons why many developers
choose to use Clojure. All data is immutable unless
explicitly marked as
mutable by using the reference types
Var<http://java.ociweb.com/mark/clojure/article.html#Vars>
, Ref <http://java.ociweb.com/mark/clojure/article.html#Refs>,
Atom<http://java.ociweb.com/mark/clojure/article.html#Atoms>
and Agent <http://java.ociweb.com/mark/clojure/article.html#Agents>.
These provide safe ways to manage shared state and are described in the next
section titled "Reference
Types<http://java.ociweb.com/mark/clojure/article.html#ReferenceTypes>
".
Niels
http://nielsmayer.com