Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package benchmark;
 
 import org.mapdb.*;
 
 import java.io.File;
 import java.util.Map;
Test basic CRUD operations with multiple threads
public class Basic_ParallelThread {
    static final int MAX = (int) 1e8;
    static final String path = "/home/plain/db"+System.currentTimeMillis();
    static final int THREAD_NUM = 4;
    public static void main(String[] argsthrows InterruptedException {
        DB db = DBMaker.newFileDB(new File())
                .writeAheadLogDisable()
                .asyncWriteDisable()
                .make();
        final Map m = db.createTreeMap("test",32,true,false..,null);
        long time = System.currentTimeMillis();
        //insert
        for(Integer ii=0;ii<;ii++){
            m.put(ii"aaadqw "+ii);
        }
        long time2 = System.currentTimeMillis();
        ..println("INSERT: "+(time2 - time));
        time = time2;
        //RANDOM READS
        final AtomicInteger i = new AtomicInteger(0);
        ExecutorService exec = Executors.newFixedThreadPool();
        for(int j=0;j<;j++){
            exec.submit(new Runnable() {
                @Override
                public void run() {
                    while(i.incrementAndGet()<){
                        m.get(..nextInt());
                    }
                }
            });
        }
        exec.shutdown();
        exec.awaitTermination(1, .);
        time2 = System.currentTimeMillis();
        ..println("READS: "+(time2 - time));
        time = time2;
        //RANDOM UPDATES
        i.set(0);
        exec = Executors.newFixedThreadPool();
        for(int j=0;j<;j++){
            exec.submit(new Runnable() {
                @Override
                public void run() {
                    while(i.incrementAndGet()<){
                        m.put(..nextInt(), "asdasdasdasd"+i);
                    }
                }
            });
        }
        exec.shutdown();
        exec.awaitTermination(1, .);
        time2 = System.currentTimeMillis();
        ..println("UPDATES: "+(time2 - time));
        time = time2;
        db.close();
    }
New to GrepCode? Check out our FAQ X