File: README.md

package info (click to toggle)
multiverse-core 0.7.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,784 kB
  • sloc: java: 59,009; xml: 1,717; sh: 13; makefile: 5
file content (55 lines) | stat: -rw-r--r-- 1,778 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Multiverse Software Transactional Memory
-------------------------

A software transactional memory implementation for the JVM. Access (read and writes) to shared memory is done through
transactional references, that can be compared to the AtomicReferences of Java. Access to these references will be done
under A (atomicity), C (consistency), I (isolation) semantics. For more information see <a href="http://multiverse.codehaus.org">multiverse.codehaus.org</a>

Example
-------------------------

    import org.multiverse.api.references.*;
    import static org.multiverse.api.StmUtils.*;

    public class Account{
        private final TxnRef<Date> lastModified = newTxnRef();
        private final TxnLong amount = newTxnLong();

        public Account(long amount){
           this.amount.set(amount);
           this.lastModified.set(new Date());
        }

        public Date getLastModifiedDate(){
            return lastModified.get();
        }

        public long getAmount(){
            return amount.get();
        }

        public static void transfer(final Account from, final Account to, final long amount){
            atomic(new Runnable()){
                public void run(){
                    Date date = new Date();

                    from.lastModified.set(date);
                    from.amount.dec(amount);

                    to.lastModified.set(date);
                    to.amount.inc(amount);
                }
            }
        }
    }

    And it can be called like this:

    Account account1 = new Account(10);
    Account account2 = new Account(20)
    Account.transfer(account1, account2, 5);


No instrumentation.
-------------------------
Multiverse doesn't rely on instrumentation, so is easy to integrate in existing projects.