Java 8 ConcurrentHashMap - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ConcurrentHashMap class.

This code example shows how to use the following methods:
package com.taobao.oceanbase.network; 
 
import java.net.SocketAddress; 
import java.util.concurrent.ConcurrentHashMap; 
import java.util.concurrent.ConcurrentMap; 
import java.util.concurrent.TimeUnit; 
import java.util.concurrent.locks.ReentrantLock; 
 
public abstract class SessionFactory { 
 
	private ConcurrentMap<SocketAddress, Session> cache = new ConcurrentHashMap<SocketAddress, Session>();
 
	private ReentrantLock lock = new ReentrantLock();
 
	public Session getSession(Server server, SocketAddress address,
			int timeout, TimeUnit unit) {
		Session session = cache.get(address);
		if (session != null)
			return session;
		lock.lock();

10
CodeRank
This code example shows how to use the following methods:
    public static <K, V> ConcurrentMap<K, V> newConcurrentMapWithAggressiveConcurrency() {
        return new ConcurrentHashMap<>(16, 0.75f, aggressiveConcurrencyLevel);
    } 
 
    public static <K, V> ConcurrentMap<K, V> newConcurrentMap() {
        return new ConcurrentHashMap<>();
    } 
 
    /** 
     * Creates a new CHM with an aggressive concurrency level, aimed at highly updateable long living maps. 
     */ 
    public static <V> ConcurrentMapLong<V> newConcurrentMapLongWithAggressiveConcurrency() { 
        return new ConcurrentHashMapLong<>(ConcurrentCollections.<Long, V>newConcurrentMapWithAggressiveConcurrency());
    } 
 
    public static <V> ConcurrentMapLong<V> newConcurrentMapLong() { 
        return new ConcurrentHashMapLong<>(ConcurrentCollections.<Long, V>newConcurrentMap());
    } 
 
    public static <V> Set<V> newConcurrentSet() {
10
CodeRank
This code example shows how to use the following methods:get, putIfAbsent
 
    public void subscribe(final String topic, final String group, final int maxSize,
            final MessageListener messageListener, final ConsumerMessageFilter consumerMessageFilter)
                    throws MetaClientException { 
        final ConcurrentHashMap<String, SubscriberInfo> topicSubsriberRegistry = this.getTopicSubscriberRegistry(group);
        SubscriberInfo info = topicSubsriberRegistry.get(topic);
        if (info == null) {
            info = new SubscriberInfo(messageListener, consumerMessageFilter, maxSize);
            final SubscriberInfo oldInfo = topicSubsriberRegistry.putIfAbsent(topic, info);
            if (oldInfo != null) {
                throw new MetaClientException("Topic=" + topic + " has been subscribered by group " + group);
            } 
        } 
        else { 
            throw new MetaClientException("Topic=" + topic + " has been subscribered by group " + group);
        } 
    } 
 
 
    private ConcurrentHashMap<String, SubscriberInfo> getTopicSubscriberRegistry(final String group)

9
CodeRank
This code example shows how to use the following methods:
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
 
public final class MockInternalEngine extends InternalEngine implements Engine { 
    public static final ConcurrentMap<AssertingSearcher, RuntimeException> INFLIGHT_ENGINE_SEARCHERS = new ConcurrentHashMap<>();
    public static final String WRAP_READER_RATIO = "index.engine.mock.random.wrap_reader_ratio";
    public static final String READER_WRAPPER_TYPE = "index.engine.mock.random.wrapper";
 
    private final Random random;
    private final boolean wrapReader;
    private final Class<? extends FilterDirectoryReader> wrapper;
 
    @Inject 
    public MockInternalEngine(ShardId shardId, @IndexSettings Settings indexSettings, ThreadPool threadPool,
                              IndexSettingsService indexSettingsService, ShardIndexingService indexingService, @Nullable IndicesWarmer warmer, Store store,
                              SnapshotDeletionPolicy deletionPolicy, Translog translog, MergePolicyProvider mergePolicyProvider,
                              MergeSchedulerProvider mergeScheduler, AnalysisService analysisService, SimilarityService similarityService,
                              CodecService codecService) throws EngineException {
        super(shardId, indexSettings, threadPool, indexSettingsService, indexingService, warmer, store,
10
CodeRank
This code example shows how to use the following methods:
    private boolean diskCacheEnabled = false;
    private ExecutorService writeThread;
 
    public WebImageCache(Context context) {
        // Set up in-memory cache store 
        memoryCache = new ConcurrentHashMap<String, SoftReference<Bitmap>>();
 
        // Set up disk cache store 
        Context appContext = context.getApplicationContext();
        diskCachePath = appContext.getCacheDir().getAbsolutePath() + DISK_CACHE_PATH;
 
        File outFile = new File(diskCachePath);
        outFile.mkdirs();
 
        diskCacheEnabled = outFile.exists();
 
        // Set up threadpool for image fetching tasks 
        writeThread = Executors.newSingleThreadExecutor();
    } 
 
10
CodeRank
This code example shows how to use the following methods:
  private Map<String, Object> contextData;
 
  @Override 
  public Map<String, Object> contextData() {
    if (contextData == null) { 
      contextData = new ConcurrentHashMap<>();
    } 
    return contextData; 
  } 
 
 
} 
10
CodeRank
This code example shows how to use the following methods:
 
import java.util.Map; 
import java.util.concurrent.ConcurrentHashMap; 
 
public class AddCustomRequestHeaderCommand extends Command { 
  private static Map<String, String> headers = new ConcurrentHashMap<String, String>();
 
  private String key;
  private String value;
 
  public AddCustomRequestHeaderCommand(String key, String value) {
    this.key = key;
    this.value = value;
  } 
 
  @Override 
  public String execute() {
    headers.put(key, value);
 
    return "OK"; 
10
CodeRank
This code example shows how to use the following methods:get, putIfAbsent
     * @return An instance of the AnnotationValidator. 
     * 
     * @since 4.12 
     */ 
    public AnnotationValidator createAnnotationValidator(ValidateWith validateWithAnnotation) {
        AnnotationValidator validator = VALIDATORS_FOR_ANNOTATION_TYPES.get(validateWithAnnotation);
        if (validator != null) {
            return validator;
        } 
 
        Class<? extends AnnotationValidator> clazz = validateWithAnnotation.value();
        if (clazz == null) {
            throw new IllegalArgumentException("Can't create validator, value is null in annotation " + validateWithAnnotation.getClass().getName());
        } 
        try { 
            AnnotationValidator annotationValidator = clazz.newInstance();
            VALIDATORS_FOR_ANNOTATION_TYPES.putIfAbsent(validateWithAnnotation, annotationValidator);
            return VALIDATORS_FOR_ANNOTATION_TYPES.get(validateWithAnnotation);
        } catch (Exception e) {
            throw new RuntimeException("Exception received when creating AnnotationValidator class " + clazz.getName(), e);

8
CodeRank
This code example shows how to use the following methods:get, putIfAbsent
    public <T> LocalLockMediator<T> get(String namespace, TimestampProvider times) { 
 
        Preconditions.checkNotNull(namespace); 
 
        @SuppressWarnings("unchecked") 
        LocalLockMediator<T> m = (LocalLockMediator<T>)mediators.get(namespace); 
 
        if (null == m) { 
            m = new LocalLockMediator<T>(namespace, times); 
            @SuppressWarnings("unchecked") 
            LocalLockMediator<T> old = (LocalLockMediator<T>)mediators.putIfAbsent(namespace, m); 
            if (null != old) 
                m = old; 
            else 
                log.debug("Local lock mediator instantiated for namespace {}", 
                        namespace); 
        } 
 
        return m; 
    } 
8
CodeRank
This code example shows how to use the following methods:
 
  public static final String LOGGER_DELEGATE_FACTORY_CLASS_NAME = "vertx.logger-delegate-factory-class-name";
 
  private static volatile LogDelegateFactory delegateFactory;
 
  private static final ConcurrentMap<String, Logger> loggers = new ConcurrentHashMap<>();
 
  static { 
    initialise(); 
  } 
 
  public static synchronized void initialise() { 
    LogDelegateFactory delegateFactory;
 
    // If a system property is specified then this overrides any delegate factory which is set 
    // programmatically - this is primarily of use so we can configure the logger delegate on the client side. 
    // call to System.getProperty is wrapped in a try block as it will fail if the client runs in a secured 
    // environment 
    String className = JULLogDelegateFactory.class.getName();
    try { 
10
CodeRank
See Code Examples for Java 8 ConcurrentHashMap Methods: