package org.mapdb;

import org.junit.Test;

import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;

public class BTreeMapParTest {


    final int threadNum = 6;
    final int max = (int) 1e6;

    @Test
    public void parInsert() throws InterruptedException {

        ExecutorService s = Executors.newCachedThreadPool();
        final ConcurrentMap m = DBMaker.newMemoryDB().transactionDisable().make()
                .createTreeMap("test")
                .valueSerializer(Serializer.LONG)
                .makeLongMap();

        long t = System.currentTimeMillis();

        for(int j=0;j<threadNum;j++){
            final long core = j;
            s.submit(new Runnable() {
                @Override public void run() {
                    for(Long n=core;n<max;n+=threadNum){
                        m.put(n,n);
                    }
                }
            });


        }

        s.shutdown();
        s.awaitTermination(1000, TimeUnit.SECONDS);

        System.out.printf("  Threads %d, time %,d\n",threadNum,System.currentTimeMillis()-t);


        assertEquals(max,m.size());
    }
}

@@ -65,29 +65,17 @@
 current.
-ConcurrentMap
+*
 ;%0Aimport
@@ -100,100 +100,25 @@
 ent.
-ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.TimeUnit
+atomic.AtomicLong
 ;%0A%0Ai
@@ -329,68 +329,8 @@
  %7B%0A%0A
-        ExecutorService s = Executors.newCachedThreadPool();
 %0A   
@@ -497,16 +497,72 @@
 r.LONG)%0A
+                .keySerializer(BTreeKeySerializer.LONG)%0A
         
@@ -627,25 +627,24 @@
 meMillis();%0A
-%0A
         for(
@@ -644,158 +644,234 @@
    f
-or(int j=0;j%3CthreadNum;j++)%7B%0A            final long core = j;%0A            s.submit(new Runnable() %7B%0A                @Override public void run() %7B%0A    
+inal AtomicLong counter = new AtomicLong();%0A%0A        Exec.execNTimes(threadNum, new Callable() %7B%0A            @Override%0A            public Object call() throws Exception %7B%0A                long core = counter.getAndIncrement();%0A
     
@@ -889,30 +889,39 @@
  for
+ 
 (Long n
-=
+ = 
 core;
-n%3C
+ n %3C 
 max;
-n
+ n 
 +=
+ 
 thre
@@ -926,16 +926,17 @@
 readNum)
+ 
 %7B%0A      
@@ -953,20 +953,16 @@
     
-   
- 
 m.put(n,
 n);%0A
@@ -957,16 +957,17 @@
 m.put(n,
+ 
 n);%0A    
@@ -970,37 +970,34 @@
                 
-   
- 
 %7D
+%0A
 %0A               
@@ -997,17 +997,28 @@
         
-%7D
+return null;
 %0A       
@@ -1023,20 +1023,16 @@
        %7D
-);%0A%0A
 %0A       
@@ -1037,85 +1037,14 @@
    %7D
-%0A%0A        s.shutdown();%0A        s.awaitTermination(1000, TimeUnit.SECONDS
 );%0A%0A
+//
     

update btreemap concurrent test