Skip to content

Instantly share code, notes, and snippets.

@nha
Last active August 29, 2015 13:55
Show Gist options
  • Save nha/8720384 to your computer and use it in GitHub Desktop.
Save nha/8720384 to your computer and use it in GitHub Desktop.
lock-free config file
package com.github.nha;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class Configuration<K, V> {
private Map<K, V> map;
public Configuration() {
this.map = new ConcurrentHashMap<K, V>();
}
public void putValue(K key, V string) {
this.map.put(key, string);
}
public V getValue(K key) {
return this.map.get(key);
}
// ...
public static void main(String[] args) {
Configuration<String, String> config = new Configuration<String, String>();
config.putValue("kikoo", "world!");
config.putValue("fooKey", "fooValue");
config.putValue("barKey", "barValue");
System.out.println("kikoo " + config.getValue("kikoo")); // prints "kikoo world!"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment