Alternative to Actor model

My main experience working with multithread environment was using Scala, so if I had an object that was concurrently updated by multiple threads I always used Akka. Now working in Java environment I don’t want to bring all Akka dependencies and futures complications for a simple case where I have a concurrently updated object. I question myself, what is the accepted alternative besides Actor model for sharing updateable state between threads?

1

Three paradigms in common use are actors (e.g. Akka), Software Transactional Memory (e.g. Clojure) or traditional manual lock-wrangling. They all have their own challenges.

Traditional lock-based programming involves detecting the places that need protection from corruption via concurrent accesses, protect them via locks, and hope that your solution is correct, deadlock-free and efficient. (Venkat Subramaniam calls this “synchronize and suffer”). There are a lot of problems with this approach: many languages give you virtually no help in ensuring correctness. Development doesn’t scale because thread-safety isn’t preserved under composition (every time you change anything about your code you have to re-prove that the solution is correct). Although this model underlies all other models, it is effectively the assembler programming of concurrency, and just as unpleasant to work with.

Actors you already know. The fundamental concepts here are asynchronous messages and exclusive responsibility of an actor for its bit of mutable state. The watchword is isolated mutability. One of the problems with this is that it can get very inefficient if one of the resources hidden behind an actor is a bottleneck. And it’s still possible to create deadlocks when using actors improperly.

Software Transactional Memory is best viewed as shared immutability. The usual explanation is that every thread just does what it wants to do and a monitor undoes the entire sequence of one thread if it detects that a conflict has actually occurred. A nice metaphor is updating a web service with no downtime: you simply set up a second, identical server, upgrade that, and if it worked you throw a switch to redirect all traffic to the new address and shut down the old one. If something unforeseen happened (e.g. requirements changed before you were done upgrading) you simply discard the new server and start over.

The disadvantage with STM is that all the copying needed to maintain immutability can get expensive, and programming it can be really hard to understand. STM is basically lock-free programming with a vengeance, and lock-free programming is hard on many people’s minds as it is. It often requires finding new algorithms for problems that you thought were already solved long ago. And again, it’s efficient only as long as conflicts and rollbacks are relatively rare.

Which model to choose depends on many factors; my personal impression is that tool support is actually more important than the underlying paradigm. It’s a lot easier to program with an unfamiliar paradigm with good language support than a familiar one with next to none.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật