Created
January 27, 2016 09:59
-
-
Save danielshaya/1561a5380d142c8b5ad8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test; | |
import net.openhft.chronicle.map.ChronicleMap; | |
import net.openhft.chronicle.map.ChronicleMapBuilder; | |
import net.openhft.lang.model.DataValueClasses; | |
import net.openhft.lang.values.LongValue; | |
import java.io.File; | |
import java.io.IOException; | |
public class ChMapDemoAdvanced { | |
public void demoOffHeapReference() throws IOException { | |
//Build the map: Not the actual interface which is a ConcurrentMap | |
ChronicleMap<String, LongValue> demoMap = | |
ChronicleMapBuilder.of(String.class, LongValue.class) | |
.entries(10_000) //the maximum number of entries for the map | |
.averageKeySize(32) //the average number of bytes for the key | |
.createPersistedTo(new File("/tmp/demodir", "demomap1")); | |
//The LongValue is direct value backed by off heap memory | |
LongValue userRequests = DataValueClasses.newDirectInstance(LongValue.class); | |
//Get the number of requests associated with "users1" using the variable 'userRequest'. | |
//Note the zero garbage technique | |
demoMap.acquireUsing("user1", userRequests); | |
//increment the number requests which is automatically saved to disk | |
userRequests.addValue(1); | |
System.out.println("user1 has made " + userRequests.getValue() + " requests."); | |
} | |
public static void main(String[] args) throws IOException { | |
ChMapDemoAdvanced chMapDemo = new ChMapDemoAdvanced(); | |
chMapDemo.demoOffHeapReference(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment