Package org.mapdb

Examples of org.mapdb.HTreeMap


        final double cacheSizeInGB = 1.0;

        // Create cache backed by off-heap store
        // In this case store will use ByteBuffers backed by byte[].
        HTreeMap cache = DBMaker.newCache(cacheSizeInGB);

        // Other alternative is to use Direct ByteBuffers.
        // In this case the memory is not released if cache is not correctly closed.

        //  cache = DBMaker.newCacheDirect(cacheSizeInGB);

        //generates random key and values
        Random r = new Random();
        //used to print store statistics
        Store store = Store.forEngine(cache.getEngine());


        // insert some stuff in cycle
        for(long counter=1; counter<1e8; counter++){
            long key = r.nextLong();
            byte[] value = new byte[1000];
            r.nextBytes(value);

            cache.put(key,value);

            if(counter%1e5==0){
                System.out.printf("Map size: %,d, counter %,d, store size: %,d, store free size: %,d\n",
                        cache.sizeLong(), counter, store.getCurrSize(),  store.getFreeSize());
            }

        }

        // and release memory. Only necessary with `DBMaker.newCacheDirect()`
        cache.close();

    }
View Full Code Here


                .transactionDisable()   //better performance
                .make();

        //create map, entries are expired if not accessed (get,iterate) for 10 seconds or 30 seconds after 'put'
        //There is also maximal size limit to prevent OutOfMemoryException
        HTreeMap map = db
                .createHashMap("cache")
                .expireMaxSize(1000000)
                .expireAfterWrite(30, TimeUnit.SECONDS)
                .expireAfterAccess(10, TimeUnit.SECONDS)
                .make();

        //load stuff
        for(int i = 0;i<100000;i++){
            map.put(i, randomString(1000));
        }

        //one can monitor two space usage numbers:

        //free space in store
View Full Code Here

TOP

Related Classes of org.mapdb.HTreeMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.