Example usage for java.util Collections synchronizedMap

List of usage examples for java.util Collections synchronizedMap

Introduction

In this page you can find the example usage for java.util Collections synchronizedMap.

Prototype

public static <K, V> Map<K, V> synchronizedMap(Map<K, V> m) 

Source Link

Document

Returns a synchronized (thread-safe) map backed by the specified map.

Usage

From source file:bboss.org.apache.velocity.runtime.resource.ResourceCacheImpl.java

/**
 * @see bboss.org.apache.velocity.runtime.resource.ResourceCache#initialize(bboss.org.apache.velocity.runtime.RuntimeServices)
 */// w  w  w.  jav  a 2s .  c  o m
public void initialize(RuntimeServices rs) {
    rsvc = rs;

    int maxSize = rsvc.getInt(RuntimeConstants.RESOURCE_MANAGER_DEFAULTCACHE_SIZE, 89);
    if (maxSize > 0) {
        // Create a whole new Map here to avoid hanging on to a
        // handle to the unsynch'd LRUMap for our lifetime.
        Map lruCache = Collections.synchronizedMap(new LRUMap(maxSize));
        lruCache.putAll(cache);
        cache = lruCache;
    }
    rsvc.getLog().debug(
            "ResourceCache: initialized (" + this.getClass() + ") with " + cache.getClass() + " cache map.");
}

From source file:org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer.java

/**
 * Instantiates the plugin container. All subclasses must support this and only this
 * constructor.// w ww. j ava  2 s  . c o  m
 *
 * @param master the master plugin container that is creating this instance.
 */
public AbstractTypeServerPluginContainer(MasterServerPluginContainer master) {
    this.master = master;
    this.loadedTimestamps = Collections.synchronizedMap(new HashMap<PluginKey, Long>());
}

From source file:com.rockhoppertech.music.chord.ChordFactory.java

static void init() {
    midiChords = new ArrayList<Chord>();
    midiChordMap = Collections.synchronizedMap(new LinkedHashMap<String, Chord>());
    try {// w ww.  j  a  v  a  2s  .c om
        ChordFactoryXMLHelper.setDefinitionFileName(definitionFileName);
        loadDefinitions();
    } catch (Exception e) {
        if (logger.isErrorEnabled()) {
            logger.error("loading defs", e);
        }
    }
}

From source file:com.yahoo.glimmer.web.Querier.java

public Querier() {
    LinkedHashMap<String, Long> idCache = new LinkedHashMap<String, Long>(CACHE_SIZE + 1, 1.1f, true) {
        private static final long serialVersionUID = -8171861525079261380L;

        protected boolean removeEldestEntry(java.util.Map.Entry<String, Long> eldest) {
            return size() > CACHE_SIZE;
        };//from   www. j  a  v  a 2  s.  c  om
    };
    objectsSubjectsIdCache = Collections.synchronizedMap(idCache);

    LinkedHashMap<Long, String> labelCache = new LinkedHashMap<Long, String>(CACHE_SIZE + 1, 1.1f, true) {
        private static final long serialVersionUID = -6916960713013021549L;

        protected boolean removeEldestEntry(java.util.Map.Entry<Long, String> eldest) {
            return size() > CACHE_SIZE;
        };
    };
    objectLabelCache = Collections.synchronizedMap(labelCache);
}

From source file:gov.nih.nci.integration.invoker.CaTissueConsentServiceInvocationStrategy.java

/**
 * Constructor/*from w ww  .j a  va 2 s  .  co m*/
 * 
 * @param retryCount - retryCount
 * @param caTissueSpecimenClient -caTissueSpecimenClient
 * @param xsltTransformer - xsltTransformer
 */
public CaTissueConsentServiceInvocationStrategy(int retryCount, CaTissueConsentClient caTissueSpecimenClient,
        XSLTTransformer xsltTransformer) {
    super();
    this.retryCount = retryCount;
    this.caTissueConsentClient = caTissueSpecimenClient;
    this.xsltTransformer = xsltTransformer;

    final HashMap<String, IntegrationError> msgToErrMapBase = new LinkedHashMap<String, IntegrationError>();
    msgToErrMapBase.put("Specimen for given LABEL doesn't exist", IntegrationError._1090);
    msgToErrMapBase.put("Collection Protocol was not found in caTissue", IntegrationError._1091);
    msgToErrMapBase.put("ConsentTier Statement was not found for given CollectionProtocol in caTissue",
            IntegrationError._1092);
    msgToErrMapBase.put("Error occurred : Unable to rollback. Please check the logs.", IntegrationError._1093);
    msgToErrMapBase.put("Exception occurred while XSL transformation.", IntegrationError._1099);

    msgToErrMap = Collections.synchronizedMap(msgToErrMapBase);
}

From source file:it.units.malelab.ege.core.listener.PropertiesListener.java

public PropertiesListener(Comparator<F> fitnessComparator, Distance<G> genotypeDistance,
        Distance<Node<T>> phenotypeDistance, Map<Class<? extends GeneticOperator>, String> operatorNames) {
    super(MappingEvent.class, OperatorApplicationEvent.class, EvolutionStartEvent.class);
    this.fitnessComparator = fitnessComparator;
    this.genotypeDistance = genotypeDistance;
    this.phenotypeDistance = phenotypeDistance;
    this.operatorNames = operatorNames;
    partialDistances = (Map) Collections.synchronizedMap(new LinkedHashMap<>());
    cumulativeDistances = (Map) Collections.synchronizedMap(new LinkedHashMap<>());
    counts = (Map) Collections.synchronizedMap(new LinkedHashMap<>());
    //reset data/*from w  w  w  .j av  a2s.c  o m*/
    counts.put(NO_OPERATOR, (Multiset) ConcurrentHashMultiset.create());
    for (String operatorName : operatorNames.values()) {
        counts.put(operatorName, (Multiset) ConcurrentHashMultiset.create());
        partialDistances.put(operatorName, Collections.synchronizedList(new ArrayList<Pair<Double, Double>>()));
        cumulativeDistances.put(operatorName,
                Collections.synchronizedList(new ArrayList<Pair<Double, Double>>()));
    }
}

From source file:org.jdesktop.wonderland.modules.service.InstallManager.java

/**
 * Constructor, takes the root directory of the module manager
 *///  w ww  . j av a  2  s  .  co  m
public InstallManager(File root) {
    /* Create the installed directory if it does not exist */
    this.installedFile = new File(root, installed_DIR);
    try {
        ModuleManagerUtils.makeDirectory(this.installedFile);
    } catch (java.io.IOException excp) {
        ModuleManager.getLogger().log(Level.SEVERE, "[MODULES] Failed to Create installed Directory ", excp);
    }

    /* Read the map of installed modules */
    this.installedModules = Collections.synchronizedMap(this.fetchModules());
}

From source file:org.xchain.framework.scanner.ScannerLifecycle.java

public ScannerLifecycle() {
    protocolMap.put("file", new FileProtocolScanner());
    protocolMap.put("jar", new JarProtocolScanner());

    // define the vfszip, vfsfile, and vfsmemory protocols if the jboss virtual file system classes are on the classpath.
    if (isVfsDefined()) {
        protocolMap.put("vfszip", new VfsProtocolScanner());
        protocolMap.put("vfsfile", new VfsProtocolScanner());
        protocolMap.put("vfsmemory", new VfsProtocolScanner());
    }//w w  w . j  a  v a 2s .  com
    if (isZipDefined()) {
        protocolMap.put("zip", new ZipProtocolScanner());
    }
    if (isBundleDefined()) {
        protocolMap.put("bundle", new BundleProtocolScanner());
        protocolMap.put("bundleresource", new BundleProtocolScanner());
    }

    if (MEMOIZE_SCAN_NODE) {
        cache = Collections.synchronizedMap(new WeakHashMap<ClassLoader, Map<RootUrlLocator, ScanNode>>());
    }
}

From source file:org.kuali.rice.krad.util.MessageMap.java

public MessageMap() {
    errorPath = Collections.synchronizedList(new ArrayList<String>());
    errorMessages = Collections.synchronizedMap(new LinkedHashMap<String, List<ErrorMessage>>());
    warningMessages = Collections.synchronizedMap(new LinkedHashMap<String, List<ErrorMessage>>());
    infoMessages = Collections.synchronizedMap(new LinkedHashMap<String, List<ErrorMessage>>());
    growlMessages = Collections.synchronizedList(new AutoPopulatingList<GrowlMessage>(GrowlMessage.class));
}

From source file:kenh.xscript.Environment.java

/**
 * Initial method// w  w  w. j  a  v a2 s  .  co m
 */
private void initial() {

    // 
    Map<String, Element> methods = Collections.synchronizedMap(new LinkedHashMap());
    this.setVariable(KEY_METHODS, methods);

    // public
    List<String> publics = Collections.synchronizedList(new LinkedList());
    this.setVariable(KEY_PUBLIC, publics);

    // 
    List<String> constant = Collections.synchronizedList(new LinkedList());
    this.setVariable(KEY_CONSTANT, constant);

    constant.add(KEY_METHODS);
    constant.add(KEY_PUBLIC);
    constant.add(KEY_CONSTANT);

    publics.add(KEY_METHODS);
    publics.add(KEY_PUBLIC);
    publics.add(KEY_CONSTANT);

}