5

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?

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

  • using a synchronized collection (of Bs inside of A), for example from java.util.concurrent package?
  • synchronize collection reads outside transactions with the collection writes inside transactions, for example using "synchronized( collection )" code around reads and writes?
2
  • Can't really answer- It's supposed to be transactionally safe, but I'm actually using it somewhat differently (where data integrity isn't so important, just very fast access), so I haven't paid to much attention to those details. Sorry.
    – Steve B.
    Jan 18, 2009 at 2:19
  • @Steve, thanx anyway. I'm gooing to read its code again :)
    – Sergey
    Jan 18, 2009 at 8:16

2 Answers 2

4

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

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.

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.

1
  • The referenced discussion is very useful. Aug 29, 2010 at 2:40
1

It's been a really long time since I looked at Prevayler (I used it in a POC project about 6 or 7 years ago). I am pretty sure that if doing all your reads and writes through Prevayler no further synchronization is required - certainly I didn't need to in what I did, and that had multiple threads using the datastore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.