package org.mapdb;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/*
 *
 */
public class Exec {

    public static void execNTimes(int n, final Callable r){
        ExecutorService s = Executors.newFixedThreadPool(n);
        final CountDownLatch wait = new CountDownLatch(n);

        List<Future> f = new ArrayList();

        Runnable r2 = new Runnable(){

            @Override
            public void run() {
                wait.countDown();
                try {
                    wait.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                try {
                    r.call();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        };

        for(int i=0;i<n;i++){
            f.add(s.submit(r2));
        }

        s.shutdown();

        for(Future ff:f){
            try {
                ff.get();
            } catch (Exception e) {
                throw new Error(e);
            }
        }

    }
}

@@ -17,36 +17,8 @@
 b;%0A%0A
-import java.util.ArrayList;%0A
 impo
@@ -36,16 +36,16 @@
 l.List;%0A
+
 import j
@@ -309,16 +309,27 @@
 f = new 
+CopyOnWrite
 ArrayLis
@@ -329,16 +329,24 @@
 rrayList
+%3CFuture%3E
 ();%0A%0A   
@@ -925,24 +925,58 @@
 hutdown();%0A%0A
+        while(!f.isEmpty()) %7B%0A    
         for(
@@ -974,16 +974,17 @@
      for
+ 
 (Future 
@@ -989,11 +989,14 @@
 e ff
-:
+ : 
 f)
+ 
 %7B%0A  
@@ -997,38 +997,46 @@
 ) %7B%0A            
+  
+  
 try %7B%0A
+    
                 
@@ -1042,19 +1042,76 @@
  ff.get(
-);%0A
+1, TimeUnit.SECONDS);%0A                    f.remove(ff);%0A    
         
@@ -1115,32 +1115,39 @@
        %7D catch (
+Timeout
 Exception e) %7B%0A 
@@ -1137,32 +1137,106 @@
 tException e) %7B%0A
+                    //ignored%0A                %7D catch (Exception e) %7B%0A    
                 
@@ -1245,16 +1245,25 @@
 row new 
+Assertion
 Error(e)
@@ -1260,24 +1260,42 @@
 onError(e);%0A
+                %7D%0A
             
@@ -1288,32 +1288,32 @@
 %7D%0A            %7D%0A
+
         %7D%0A%0A    %7D
@@ -1302,21 +1302,20 @@
 %7D%0A        %7D%0A
-%0A
     %7D%0A%7D%0A

fix multithreaded execution