StringBuffer synchronization is not a transaction
StringBuffer synchronizes individual methods, not a sequence of calls. Compound checks and updates still need a shared lock or a different concurrency design.
"StringBuffer synchronization is not a transaction" is a useful thing to know about with java / strings. Thanks for sharing it.
- @saltysamm▲ 2
"StringBuffer synchronization is not a transaction" is a useful thing to know about with java / strings. Thanks for sharing it.
Lifesaver
- @deneil2121▲ 2
Smart
Lifesaver
- @sohmeh▲ 1
Clear note on java / strings. "StringBuffer synchronization is not a transaction" is the kind of detail that is easy to overlook.
Great
Each StringBuffer method is synchronized on its own, so a check followed by an update can still race with other threads. A shared lock around the whole sequence, or a different design, is needed for that logic.
To make a multi-call sequence atomic on a
StringBuffer, lock the same object the methods synchronize on, which is the buffer instance itself. Other platform gotchas welcome in the comments."StringBuffer synchronization is not a transaction" is a useful thing to know about with java / strings. Thanks for sharing it.
Appreciate the write-up on "StringBuffer synchronization is not a transaction". Useful for anyone using java / strings.
Appreciate the write-up on "StringBuffer synchronization is not a transaction". Useful for anyone using java / strings.
Appreciate the write-up on "StringBuffer synchronization is not a transaction". Useful for anyone using java / strings.