| 1 |
<h1>Frequent asked questions</h1> |
| 2 |
|
| 3 |
<ol> |
| 4 |
<li><a href="#question.1">Does Multiverse rely on instrumentation?</a></li> |
| 5 |
<li><a href="#question.2">Can Multiverse be used with different languages?</a></li> |
| 6 |
<li><a href="#question.3">Can I use arbitrary threads?</a></li> |
| 7 |
<li><a href="#question.4">Can multiple STM instances be used within the same JVM?</a></li> |
| 8 |
<li><a href="#question.5">Do I need a special JVM?</a></li> |
| 9 |
<li><a href="#question.6">Can the changes be persisted?</a></li> |
| 10 |
<li><a href="#question.7">Can Multiverse be distributed?</a></li> |
| 11 |
<li><a href="#question.8">Which License is used?</a></li> |
| 12 |
<li><a href="#question.9">Does Multiverse support blocking transactions?</a></li> |
| 13 |
<li><a href="#question.10">Does Multiverse scale linearly?</a></li> |
| 14 |
<li><a href="#question.11">Does Multiverse prevent deadlocking?</a></li> |
| 15 |
<li><a href="#question.12">Does Multiverse prevent livelocking?</a></li> |
| 16 |
<li><a href="#question.13">Does Multiverse prevent starvation?</a></li> |
| 17 |
<li><a href="#question.14">Can Multiverse transactions participate in a distributed transaction?</a></li> |
| 18 |
<li><a href="#question.15">Does Multiverse suffer from Zombie threads?</a></li> |
| 19 |
<li><a href="#question.16">Can non transactional objects be used in transactions?</a></li> |
| 20 |
<li><a href="#question.17">Can IO be done in transactions?</a></li> |
| 21 |
<li><a href="#question.18">Does Multiverse provide support for pessimistic locking?</a></li> |
| 22 |
<li><a href="#question.19">Does Multiverse support nesting of transactions?</a></li> |
| 23 |
<li><a href="#question.20">Does Multiverse allow non transactional access?</a></li> |
| 24 |
<li><a href="#question.21">Does Multiverse support early or late conflict detection?</a></li> |
| 25 |
<li><a href="#question.22">Does Multiverse support direct or deferred updates?</a></li> |
| 26 |
<li><a href="#question.23">Can Multiverse be combined with traditional lock based technology?</a></li> |
| 27 |
<li><a href="#question.24">Are Multiverse Transactions thread-safe?</a></li> |
| 28 |
<li><a href="#question.25">Is lock based concurrency control bad?</a></li> |
| 29 |
<li><a href="#question.26">Multiverse and the Java Memory Model</a></li> |
| 30 |
<li><a href="#question.27">Does Multiverse have object or field granularity?</a></li> |
| 31 |
<li><a href="#question.28">Can Multiverse be combined with Spring/Guice/...?</a></li> |
| 32 |
</ol> |
| 33 |
|
| 34 |
<h2 id="question.1">Does Multiverse rely on instrumentation</h2> |
| 35 |
No; it doesn't. Although instrumentation makes a cleaner integration in Java possible, it is a hassle to integrate |
| 36 |
in real projects. So instrumentation has been dropped. |
| 37 |
|
| 38 |
<h2 id="question.2">Can Multiverse be used with different languages?</h2> |
| 39 |
Multiverse can be used with different Java based languages like Groovy or Scala. For Groovy integration see the |
| 40 |
<a href="http://gpars.codehaus.org/">GPars</a> project. |
| 41 |
|
| 42 |
<h2 id="question.3">Can I use arbitrary threads?</h2> |
| 43 |
Yes you can. Multiverse doesn't require any special threads or any special settings on threads. |
| 44 |
|
| 45 |
<h2 id="question.4">Can multiple STM instances be used within the same JVM?</h2> |
| 46 |
Yes you can. But each transactional object only belongs to a single STM instance. If you combine different STM's you |
| 47 |
will get exceptions. |
| 48 |
|
| 49 |
<h2 id="question.5">Do I need a special JVM?</h2> |
| 50 |
No you don't. You can use an ordinary Java 1.6+ JVM like the JVM from Sun/Oracle or IBM. |
| 51 |
|
| 52 |
<h2 id="question.6">Can the changes be persisted?</h2> |
| 53 |
No, for the moment this isn't possible. But hooking some kind of persistance mechanism up to the stm shouldn't be |
| 54 |
impossible and is planned for the future. |
| 55 |
|
| 56 |
<h2 id="question.7">Can Multiverse be distributed</h2> |
| 57 |
No, for the moment. |
| 58 |
|
| 59 |
<h2 id="question.8">Which License is used</h2> |
| 60 |
Multiverse is released under the <a href="license.html">Apache 2 License</a>. |
| 61 |
|
| 62 |
<h2 id="question.9">Does Multiverse support blocking transactions?</h2> |
| 63 |
Yes. For more information about blocking operations, check the <a href="manual-blocking.html">5 Minute guide to |
| 64 |
blocking transactions</a>. |
| 65 |
|
| 66 |
<h2 id="question.10">Does Multiverse scale linearly?</h2> |
| 67 |
It depends. With the introduction of Multiverse 0.7, there is no shared clock. So independant parts of the system |
| 68 |
can scale independantly. |
| 69 |
|
| 70 |
<h2 id="question.11">Does Multiverse prevent deadlocking?</h2> |
| 71 |
Yes. As long as transactional resources of Multiverse are used, transactions won't deadlock. There are 2 requirements |
| 72 |
for a deadlock: |
| 73 |
<ol> |
| 74 |
<li>uncontrolled order of locking</li> |
| 75 |
<li>uncontrolled waiting</li> |
| 76 |
</ol> |
| 77 |
Acquiring locks in Multiverse is done with a maximum waiting time, so the second condition for a deadlock is |
| 78 |
not present. The lock behavior can be customized by providing a custom CommitLockPolicy implementation. |
| 79 |
|
| 80 |
<h2 id="question.12">Does Multiverse prevent livelocking?</h2> |
| 81 |
Multiverse is very optimistic, so it could be that while reading/writing to transactional object a failure is encountered |
| 82 |
or when the transaction commits. The TxnExecutor automatically retries the transaction in the hope that it |
| 83 |
will succeed next time. Uncontrolled retrying could lead to livelocking because resources are consumed (memory |
| 84 |
and cpu cycles) but no progress is made because transaction keep aborting. By default a bound number of retries will be used |
| 85 |
and the livelocking transaction will eventually fail with a TooManyRetriesException. |
| 86 |
|
| 87 |
<h2 id="question.13">Does Multiverse prevent starvation?</h2> |
| 88 |
No. Multiverse doesn't provide any guarantee that transaction that content over resources are going to commit. Meaning |
| 89 |
that a transaction eventually fails with a TooManyRetriesException. A practical example of starving transactions |
| 90 |
are long running transactions, the keep conflicting on very short running transactions. In the future a |
| 91 |
contention manager is going to be added, but for the time being there is no support available. |
| 92 |
|
| 93 |
<h2 id="question.14">Does Multiverse suffer from Zombie threads?</h2> |
| 94 |
It depends. By default no zombie threads are possible, but if lower than SERIALIZED isolation level is selected, zombie |
| 95 |
threads are possible and there currently is no protection agains them. So using a lowe level isolation level should |
| 96 |
be used with care. |
| 97 |
|
| 98 |
<h2 id="question.15">Can non transactional objects be used in transactions?</h2> |
| 99 |
Yes you can. Normal objects can be used in transactions, for example a normal Person POJO be exchanged over a transactional BlockingQueue |
| 100 |
for example. But changes made on these objects won't be protected by the transaction, so you need to |
| 101 |
know what you are doing. |
| 102 |
|
| 103 |
<h2 id="question.16">Can IO be used in transactions?</h2> |
| 104 |
It is possible to do IO in a transaction, but it could be that the transaction is aborted and restarted many times |
| 105 |
(for example because a read conflict or write conflict is encountered). It is possible to register tasks to be executed |
| 106 |
when a Transaction aborts or commits, giving the option to 'undo' what is done. Support for transacional IO is planned, |
| 107 |
but doesn't have a high priority at the moment. |
| 108 |
|
| 109 |
<h2 id="question.17">Does Multiverse provide support for pessimistic locking?</h2> |
| 110 |
Yes. See the Lock and LockMode. |
| 111 |
|
| 112 |
<h2 id="question.18">Does Multiverse provide support for nesting transactions?</h2> |
| 113 |
Yes. Transactions can be nested and atm they will always be flattened (so only the outer transaction counts). An abort |
| 114 |
or commit will always be executed on the while transaction and not subtransactions. |
| 115 |
|
| 116 |
<h2 id="question.19">Does Multiverse allow non transactional access?</h2> |
| 117 |
It depends. It isn't possible to see changes made by transactions in progress (so no dirty reads). |
| 118 |
|
| 119 |
<h2 id="question.20">Does Multiverse support early or late conflict detection?</h2> |
| 120 |
It depends. |
| 121 |
|
| 122 |
<h2 id="question.21">Does Multiverse support direct or deferred updates?</h2> |
| 123 |
Multiverse only supports deferred updates, so the changes are made visible to other transaction when the transaction commits. |
| 124 |
That is why dirty reads are not possible. |
| 125 |
|
| 126 |
<h2 id="question.22">Can Multiverse be combined with traditional lock based technology?</h2> |
| 127 |
Yes, it can. But this is not without risk; changes made in non transactional resources are not protected by the STM. |
| 128 |
And blocking operations on non transactional resouces, doesnt benefit from deadlock detection, listening |
| 129 |
to multiple blocking resources, etc. So if you know what you are doing, traditional lock based technology can |
| 130 |
be combined with Multiverse. |
| 131 |
|
| 132 |
<h2 id="question.23">Are Multiverse Transactions thread-safe?</h2> |
| 133 |
No, a transaction is not thread-safe to use and therefor can't be used by multiple threads |
| 134 |
concurrently. It is possible however to hand over a transaction from one thread to another |
| 135 |
because the transation itself doesn't rely on any thread/threadlocal information. But it could |
| 136 |
be that the systems in front of the STM does rely on this. So threads |
| 137 |
can safely be handed over from one thread to another, if you really know what you are doing. |
| 138 |
<p> |
| 139 |
The org.multiverse.api.Txn can be compared to the Hibernate Session, that also isn't threadsafe to use. |
| 140 |
|
| 141 |
<h2 id="question.24">Is lock based concurrency control bad?</h2> |
| 142 |
I certainly don't think that lock based concurrency control is bad. Multiverse even couldn't exist with low |
| 143 |
level synchronization structures like locks or cas instructions (AtomicLongs for example). But I do think that |
| 144 |
lock based concurrency control is very complex; it is very easy to get in all sorts of traditional problems (race problems, |
| 145 |
deadlocks etc) even for the more experienced developer. And next these well known issues, it also is quite |
| 146 |
easy to introduce reordening or visibility problems if you don't understand the Java Memory Model well. |
| 147 |
<p> |
| 148 |
That is why I think that STM's are a very valuable tool in the toolbox of developers, that could boost |
| 149 |
productivity if used correctly. You could compare it with Hibernate and raw SQL; Hibernate makes live easy |
| 150 |
because you don't need to deal with all the SQL issues all the time. But from time to time, you need to get |
| 151 |
dirty and use SQL directly to get the things done. |
| 152 |
|
| 153 |
<h2 id="question.25">Multiverse and the Java Memory Model</h2> |
| 154 |
The Java Memory Model is defined in happens before rules, for example the volatile variable rule that states |
| 155 |
that all changes made before a volatile write, will be visible when a volatile read is done. Using this mechanism |
| 156 |
it is possible to hand over an object graph from one thread to another without worrying about visibility |
| 157 |
or reordering issues. Multiverse also provides a happens before rule: all changes made before a transaction commits, |
| 158 |
will be visible to all starting transactions. So you don't need to worry about reordering or visibility problems. |
| 159 |
<p> |
| 160 |
On a lower level this behavior is realized using CAS instructions (for example an AtomicReference) that provides |
| 161 |
the same happens before semantics as volatile variables. |
| 162 |
|
| 163 |
<h2 id="question.26">Does Multiverse have object or field granularity?</h2> |
| 164 |
Multiverse doesn't support instrumentation (anymore), so evertything will be field level granularity. |
| 165 |
|
| 166 |
<h2 id="question.27">Does Multiverse have provides support for contention management?</h2> |
| 167 |
No. Currently Multiverse doesn't provide any support for contention management. Contention management if very |
| 168 |
usefull to provide certain fairness guarantees and to prevent livelocking and will be added in the future. |
| 169 |
The big problem I currently see is that it could cause a lot of overhead and adding it all over could |
| 170 |
impact performance all over. I believe that you only should pay for something when you are using it. |
| 171 |
|
| 172 |
<h2 id="question.28">Can Multiverse be combined with Spring/Guice/...?</h2> |
| 173 |
Yes it can. But atm there is no spring TransactionManager, so you have to make use of the instrumentation |
| 174 |
or you have to make use of a more explicit approach (TransactionlReference/TransactionTemplate). |