Re: take vs. takeIfExists
John McClain <[email protected]> Tue, 18 Nov 2008 09:35:29 -0500
| Newsgroups | gmane.comp.java.sun.jini |
|---|---|
| Message-ID | <[email protected]> |
Richard Dallaway wrote: > On 18 Nov 2008, at 08:24, Asaf Lahav wrote: >> What is the difference between using take vs. takeIfExists in the >> following cases: >> >> entry = space.takeIfExists(tmpl, null, 0); >> vs. >> entry = space.take (tmpl, null, 0); > > I'd be interested to know the answer too. > > My understanding is that it makes no difference unless you're in a > transaction (which of course you're not). From p. 245 of JavaSpaces > Principles, Patterns and Practice I see: "In effect, a readIfExists > is able to 'peak inside' transactions: if a matching entry exists > within a transaction, then readIfExists will wait up until its timeout > value for a transaction to complete before it returns". (surely take > and read will behave the same way in this situation). It doesn't matter if the query is under a transaction or not - it matters if the space is a participant in any active transactions. All queries on a space will return without blocking if there is an available (available == not locked by an active transaction) entry that matches. If there is no available matching entry then read and take will block for up to their timeout, or until a matching entry becomes available, which ever comes first. The ifExists queries will always return immediately (even if the timeout is non-zero) if there are no matching entires in the space they will only block if there is an entry in the space that is not available - that is the entry is locked by a conflicting transaction - in such cases they will wait for up to the timeout for a matching entry to become available or until there are no matching entries in the space. read and talk obey the ACID properties, the ifExists queries break isolation. Does that help? -------------------------------------------------------------------------- Getting Started: http://www.jini.org/wiki/Category:Getting_Started Community Web Site: http://jini.org jini-users Archive: http://archives.java.sun.com/archives/jini-users.html Unsubscribing: email "signoff JINI-USERS" to [email protected]