Intro to Concurrency - raisercostin/software-wiki GitHub Wiki
These problems are the worst kind: are hard to debug, understood and solve. To attack them you should understand some concepts like:
- pessimistic lock - lock a resource and everyone waits to be unlocked
- optimistic lock - on save you check the last version of the data (this is a versioning/dirty mechanism)
- test-and-set
- others: multi-threading, parallelism, threads, thread locals, race conditions, locks, deadlocks, live-locks, thread safety, concurrency, mutex, semaphores, barrier, locks, latches, monitors, critical sections, rendezvous, actors, atomic operations, exclusion zone, immutability, mutual exclusion, re-entrancy, transactions, isolation level, ACID, deterministic and non-deterministic algorithms, synchronous/asynchronous operations, sync/async blocks, handlers, callbacks, Futures, Promises, Streams, ReactiveStreams
Growth Reading List
- Working Effectively With Legacy Code
- Domain Driven Design
- Refactoring: Improving the Design of Existing Code
- NoSQL Distilled
- Effective Java
- Java Puzzlers: Traps, Pitfalls, and Corner Cases
- Java Concurrency in Practice
- Concurrent Programming in Java: Design Principles and Pattern
- Beautiful Code: Leading Programmers Explain How They Think
- Java Concurrency
Concepts
Threads vs Green Threads
https://openjdk.java.net/jeps/425
reentrant
In the same thread you're not allowed to recall the same method. A() -calls-> B() -> A()
or A() -> B()
or in general you're not allowed to A() -> ... -> A()
. This means that most probably global things are stored from the function. To be reentrant the function should not store anything (see tailrec) or only store things on the stack.
- For example An XPath expression is not thread-safe and not reentrant. In other words, it is the application's responsibility to make sure that one XPathExpression object is not used from more than one thread at any given time, and while the evaluate method is invoked, applications may not recursively call the evaluate method.
volatile
synchronized
local copy
AtomicRef
Comparisons
Resources
- https://en.wikipedia.org/wiki/Thread_safety
- What every systems programmer should know about concurrency - https://assets.bitbashing.io/papers/concurrency-primer.pdf
- https://en.wikipedia.org/wiki/Concurrency_control
- https://en.wikipedia.org/wiki/Deterministic_algorithm
Java
- https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html
- https://www.javaworld.com/article/2076747/core-java/design-for-thread-safety.html
- how to properly stop a thread (by not using the deprecated stop method)
More
(by antonia)
- https://github.com/raisercostin/software-wiki/wiki/Intro-to-Concurrency
- https://docs.spring.io/spring-statemachine/docs/1.1.x/reference/html/sm-persist.html
- https://docs.spring.io/spring-statemachine/docs/1.1.x/reference/html/sm-interceptor.html
- https://www.baeldung.com/jpa-optimistic-locking
- https://www.baeldung.com/jpa-pessimistic-locking
- https://www.baeldung.com/spring-data-jpa-modifying-annotation
- https://www.baeldung.com/jpa-transaction-required-exception
- https://www.baeldung.com/spring-transactions-read-only
- https://www.baeldung.com/transaction-configuration-with-jpa-and-spring
- https://gamedevbeginner.com/state-machines-in-unity-how-and-when-to-use-them/