Re: Prevayler + BlockingQueue
Justin Sampson <[email protected]> Wed, 24 Aug 2016 16:10:38 +0000
| Newsgroups | gmane.comp.java.prevayler |
|---|---|
| Message-ID | <BN3PR05MB251694DE844E8C44D628CB24D1EA0@BN3PR05MB2516.namprd05.prod.outlook.com> |
Right -- you should _never_ do any blocking operations inside a Prevayler query or transaction, because Prevayler manages its own concurrency. In fact, _any_ nontrivial concurrency inside a transaction makes it nondeterministic anyway, which is not allowed. Your TakeDocument should ideally return an Optional<Document> and your AddDocument should ideally return a boolean, in order to report failure instead of blocking. Then you can poll by executing each transaction inside a loop, optionally adding (as Klaus suggested) separate blocking methods that do not use transactions _and_ do not actually change the state of the queue but instead simply notify the waiting thread when it might be able to proceed (which still requires a retry-loop for correctness). Cheers, Justin -----Original Message----- From: Klaus Wuestefeld [mailto:[email protected]] Sent: Wednesday, August 24, 2016 6:22 AM To: Open discussion about the Prevayler project. Subject: Re: [Prevayler-discussion] Prevayler + BlockingQueue Hi Attila, Add a WaitForDocument blocking read operation. It waits for a document but does not take it, so Take will always work immediately. Since WaitForDocument is blocking, you cannot use a Prevayler Query. You do it acessing your objects directly. Would that work? Klaus On Wed, Aug 24, 2016 at 8:21 AM, Attila Magyar <[email protected]> wrote: > Hi, > > I tried to use Prevayler on a Java BlockingQueue in a naive way, and it > didn't work the way I expected. I guess I see the reason why, but I'm still > not sure how should I use it. > > Here is an example code I wrote it > > https://gist.github.com/zeroflag/8c7333e96ab9b8c8a09fa0a3b08bb907 > > There are 2 commands. AddDocument adds a new document to the queue, > TakeDocument removes a document from the queue. Both operations blocks the > current thread, and probably this is the problem. I assume prevayler uses > locks on each transactions therefore taking document from an empty queue > blocks other threads from adding a new document. > > My goal is to have a simple persistent (blocking) queue. > > Is there any simple way to make this work, or what other options do I have? > > thanks > Attila > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > To unsubscribe go to the end of this page: > http://lists.sourceforge.net/lists/listinfo/prevayler-discussion > _______________________________________________ > "Databases in Memoriam" -- http://www.prevayler.org > -- Valeu, Klaus. ------------------------------------------------------------------------------ _______________________________________________ To unsubscribe go to the end of this page: http://lists.sourceforge.net/lists/listinfo/prevayler-discussion _______________________________________________ "Databases in Memoriam" -- http://www.prevayler.org ------------------------------------------------------------------------------ _______________________________________________ To unsubscribe go to the end of this page: http://lists.sourceforge.net/lists/listinfo/prevayler-discussion _______________________________________________ "Databases in Memoriam" -- http://www.prevayler.org