@@ -0,0 +1,2826 @@
+package com.vladmihalcea.book.hpjp.hibernate.concurrency.acid;%0A%0Aimport com.vladmihalcea.book.hpjp.util.AbstractTest;%0Aimport org.junit.Test;%0A%0Aimport javax.persistence.Entity;%0Aimport javax.persistence.Id;%0Aimport javax.persistence.Table;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.concurrent.*;%0Aimport java.util.stream.IntStream;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.fail;%0A%0A/**%0A * @author Vlad Mihalcea%0A */%0Apublic class JavaLinearizableTest extends AbstractTest %7B%0A%0A    @Override%0A    protected Class%3C?%3E%5B%5D entities() %7B%0A        return new Class%3C?%3E%5B%5D%7B%0A            Account.class%0A        %7D;%0A    %7D%0A%0A    int threadCount = 32;%0A%0A    public static ForkJoinPool forkJoinPool = ForkJoinPool.commonPool();%0A%0A    public void transfer(Account from, Account to, long transferCents) %7B%0A        long fromBalance = from.getBalance();%0A%0A        if(fromBalance %3E= transferCents) %7B%0A            from.addBalance(-1 * transferCents);%0A            to.addBalance(transferCents);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testParallelExecution() %7B%0A%0A        Account fromAccount = new Account();%0A        fromAccount.setIban(%22Alice-123%22);%0A        fromAccount.setOwner(%22Alice%22);%0A        fromAccount.setBalance(10);%0A%0A        Account toAccount = new Account();%0A        toAccount.setIban(%22Bob-456%22);%0A        toAccount.setOwner(%22Bob%22);%0A        toAccount.setBalance(0L);%0A%0A        List%3CCallable%3CVoid%3E%3E callables = new ArrayList%3C%3E();%0A%0A        for (int i = 0; i %3C threadCount; i++) %7B%0A            callables.add(() -%3E %7B%0A                transfer(fromAccount, toAccount, 5);%0A%0A                return null;%0A            %7D);%0A        %7D%0A%0A        LOGGER.info(%22Starting threads%22);%0A        List%3CFuture%3CVoid%3E%3E futures = forkJoinPool.invokeAll(callables);%0A        for (Future future : futures) %7B%0A            try %7B%0A                future.get();%0A            %7D catch (InterruptedException%7CExecutionException e) %7B%0A                fail(e.getMessage());%0A            %7D%0A        %7D%0A%0A        LOGGER.info(%22Alice's balance %7B%7D%22, fromAccount.getBalance());%0A        LOGGER.info(%22Bob's balance %7B%7D%22, toAccount.getBalance());%0A    %7D%0A%0A    public static class Account %7B%0A%0A        private String iban;%0A%0A        private String owner;%0A%0A        private long balance;%0A%0A        public String getIban() %7B%0A            return iban;%0A        %7D%0A%0A        public void setIban(String iban) %7B%0A            this.iban = iban;%0A        %7D%0A%0A        public String getOwner() %7B%0A            return owner;%0A        %7D%0A%0A        public void setOwner(String owner) %7B%0A            this.owner = owner;%0A        %7D%0A%0A        public long getBalance() %7B%0A            return balance;%0A        %7D%0A%0A        public void setBalance(long balance) %7B%0A            this.balance = balance;%0A        %7D%0A%0A        public void addBalance(long amount) %7B%0A            this.balance += amount;%0A        %7D%0A    %7D%0A%7D%0A

Add Linearizable Java test