知识库--Using Akka Refs and Transactions(124)
2017-02-26 08:02
393 查看
//Akka – Ref
Unlike Clojure, where refs were defined at the language level, Akka can’trely on any existing language support. Instead, Akka provides, as part of the akka.stm package, a managed transactional reference Ref and specialized classes for primitive types such as IntRef, LongRef, and so on. The Ref (and the specialized references) represents the managed mutable identity to an immutable value of type T. Types like Integer, Long, Double, String, and other immutable types fit the bill well to serve as value objects. If we use one of our own classes, we must make sure it’s immutable, that is, that it contains only final fields.
//Ref的使用get() swap()
We can create a managed transactional reference, which is an instance of Ref, by providing an initial value or by omitting the value, defaulting to null. To obtain the current value from the reference, use the get() method. To change the mutable identity to point to a new value, use the swap() method. These calls are performed within the transaction we provide or in their own individual transactions if none is provided.
//并发处理 HB原则
When multiple threads try to change the same managed reference, Akka ensures that changes by one are written to memory and the others are retried. The transactional facility takes care of crossing the memory barriers. That is, Akka, through Multiverse, guarantees that the changes to a managed ref committed by a transaction happen before, and are visible to, any reads of the same ref later in other transactions.
Unlike Clojure, where refs were defined at the language level, Akka can’trely on any existing language support. Instead, Akka provides, as part of the akka.stm package, a managed transactional reference Ref and specialized classes for primitive types such as IntRef, LongRef, and so on. The Ref (and the specialized references) represents the managed mutable identity to an immutable value of type T. Types like Integer, Long, Double, String, and other immutable types fit the bill well to serve as value objects. If we use one of our own classes, we must make sure it’s immutable, that is, that it contains only final fields.
//Ref的使用get() swap()
We can create a managed transactional reference, which is an instance of Ref, by providing an initial value or by omitting the value, defaulting to null. To obtain the current value from the reference, use the get() method. To change the mutable identity to point to a new value, use the swap() method. These calls are performed within the transaction we provide or in their own individual transactions if none is provided.
//并发处理 HB原则
When multiple threads try to change the same managed reference, Akka ensures that changes by one are written to memory and the others are retried. The transactional facility takes care of crossing the memory barriers. That is, Akka, through Multiverse, guarantees that the changes to a managed ref committed by a transaction happen before, and are visible to, any reads of the same ref later in other transactions.
相关文章推荐
- 知识库--Sending and Receiving Messages By Akka Using Java(139)
- 知识库--Collections and Transactions Using TransactionalMap(136)
- 知识库--Creating Transaction in Java Using Akka(124)
- Google跨机房数据同步方案 Large-scale Incremental Processing Using Distributed Transactions and Notifications
- 经典论文翻译导读之《Large-scale Incremental Processing Using Distributed Transactions and Notifications》 转载
- 经典论文翻译导读之《Large-scale Incremental Processing Using Distributed Transactions and Notifications》
- 知识库--Creating Nested Transactions By Akka 内存嵌套事务(129)
- Scalable, Distributed Systems Using Akka, Spring Boot, DDD, and Java--转
- System and method for parallel execution of memory transactions using multiple memory models, including SSO, TSO, PSO and RMO
- [Angular 2] Using events and refs
- ElasticMQ 0.7.0: Long Polling, Non-Blocking Implementation Using Akka and Spray
- Large-scale Incremental Processing Using Distributed Transactions and Notifications
- 知识库--Creating Actors By Akka Using Java(139)
- Understanding and using c pointers 第三章读书笔记
- Using Credential Management in Windows XP and Windows Server 2003 【转载】
- Using TurboVNC 0.6 and VirtualGL 2.1.4 to run OpenGL Application Remotely on CentOS
- Customize vs 2010 build settings using visual studio's macros and customized macros
- Using Vagrant and Salt Stack to deploy Nginx on DigitalOcean
- Flicker free drawing using GDI+ and C#
- Accessing List Data using the JavaScript Client OM and displaying in a Dialog