Proof of concept for STM usage (atoms, agents, STM) in management of finite stateful resources, such as limited connection resources for DB access.
- Java
- Leiningen
$ lein ring server-headless
- Access Swagger via http://localhost:3000/index.html#/api
$ lein test
Due to the try/retry-on-change nature of STM and Agents, proper usage
requires pure (side-effect free) functions. As such, concurrency
mechanics specific to CLJ fit poorly when designing an I/O based
concurrency operators. (To further emphasize this necessity, io!
is
provided as a safeguard for libraries against any injected operations
causing side effects.)
Several other options exist for writing concurrency safe code.
-
Standard Java concurrency libraries are still available and provided within the clj
locking
libraries -
Atoms/Refs may still be used to create transaction states, but the resulting code will resemble typical imperative code blocks rather than functional ones. (This is final approach used within this project.)
-
Erlang-style Actor systems may be used through several available packages, the most notable of which is the Akka wrapper okku
Copyright © 2017