Prevayler 的同步策略是什么?

What are synchronizing strategies for Prevayler?(Prevayler 的同步策略是什么?)

本文介绍了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)?

如果业务对象被读取为:

Are they possible if a business object is read as:

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

?

如果是这样,哪些同步策略对用户代码有利?

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

(假设一个业务对象 A 包含一个业务对象 Bs 的集合),

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

  • 使用同步集合(A 中的 B),例如来自 java.util.concurrent 包?
  • 同步集合读取外部事务与集合写入事务内部,例如使用围绕读写的同步(集合)"代码?

推荐答案

推荐的方式是使用 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.

如果您在高并发负载下需要更高的性能(这应该是一种罕见的情况),您确实可以使用上述细粒度锁定 - 使用同步"和 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.

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

See this discussion for more details.

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

本文标题为:Prevayler 的同步策略是什么?

基础教程推荐