|
|
|
|
|
by weavejester
4219 days ago
|
|
That's still far from a general solution. Let's consider an example. One of the classic concurrency problems is managing a bank transfer. In this problem it's important that the debit and credit operations happen atomically. If one operation fails, then both operations should fail. In Clojure, we'd write: (defn transfer [from to amount]
(dosync
(alter from - amount)
(alter to + amount)))
How would you write the same thing in Java?A lot of the problems with dealing with concurrency are in communication between threads. BlockingQueues and Executors only deal with a small subset of concurrency problems, and blocked threads are a fairly inefficient use of resources compared to async solutions. |
|