什么是Prevayler的同步策略? [英] What are synchronizing strategies for Prevayler?

查看:198
本文介绍了什么是Prevayler的同步策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Prevayler保证所有的写入(通过其事务)是同步的。但是阅读呢?

Prevayler guarantees that all the writes ( through its transactions) are synchronized. But what about reads?

如果没有使用显式同步(在用户代码中),那么脏读是可行的吗?

Is it right that dirty reads are possible if no explicit synchronizing is used (in user code)?

如果业务对象读取为:

// get the 3rd account
Accont account = (Bank)prevayler.prevalentSystem().getAccounts().get(2);

对于用户代码有好处吗?

If so what synchronizing strategies are good for a user code?

(考虑业务对象A包含业务对象B的集合),

(Consider a business object A contains a collection of business objects Bs),


  • 使用同步的集合(A中的B),例如
    来自java.util.concurrent包?


  • 集合中的事务写入事务内部,例如使用
    synchronized(collection)代码读取和写入?

推荐答案

建议的方法是使用JMatch Query和Prevayler.execute(Query)。可以直接或通过使用子类。

The recommended way is to use JMatch Query and Prevayler.execute(Query). Either directly or by using subclassing.

返回的结果必须是原始值或不可变对象。如果你计划返回可变对象,你应该使用JMatch Query来做这些深层副本。这样你得到一个系统,锁定每一个敏感的阅读与其他(明智的)读写。这可以加快和简化开发,特别是对于没有多线程编程的开发人员。

The returned results must be either primitive values or immutable objects. If you plan to return mutable objects you should subclass JMatch Query to do these deep copies. This way you get a system that locks every sensible read with other (sensible) reads and writes. This can speed up and simplify development, especially for developers without multithreaded programming expirience.

如果在高并发负载下需要更多性能,这是一种罕见的情况,你确实可以使用上述的细粒度锁定 - 使用synchronized和java.util.concurrent。

If you need more performance under high concurrent load, which is supposed to be a rare case, you indeed can use described above fine grained locking - using "synchronized" and java.util.concurrent.

请参阅此讨论了解更多详情。

这篇关于什么是Prevayler的同步策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆