Example usage for java.util.concurrent ConcurrentHashMap ConcurrentHashMap

List of usage examples for java.util.concurrent ConcurrentHashMap ConcurrentHashMap

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentHashMap ConcurrentHashMap.

Prototype

public ConcurrentHashMap() 

Source Link

Document

Creates a new, empty map with the default initial table size (16).

Usage

From source file:com.mnt.base.stream.comm.PacketProcessorManager.java

protected PacketProcessorManager(int threadSize) {

    if (enablePacketCacheQueue) {
        int packetCacheQueueSize = BaseConfiguration.getIntProperty("packet_cache_queue_size", 10000);
        //streamPacketQueue = new LinkedBlockingQueue<StreamPacket>(packetCacheQueueSize);

        streamPacketQueueMap = new ConcurrentHashMap<Integer, BlockingQueue<StreamPacket>>();
        this.maxQueueMapSize = threadSize;

        this.pushAi = new AtomicLong(0);
        this.pollAi = new AtomicLong(0);

        for (int i = 0; i < this.maxQueueMapSize; i++) {
            streamPacketQueueMap.put(i, new LinkedBlockingQueue<StreamPacket>(packetCacheQueueSize));
        }//from w  w  w. j  ava  2  s  .c o  m

        threadSize = threadSize > 0 ? threadSize : 1; // at least one thread
        initProcessorThreads(threadSize);
    }

    initProcessorMap();
}

From source file:lucee.runtime.reflection.storage.SoftMethodStorage.java

/**
 * store a class with his methods// w  w  w . j av  a2  s  . c om
 * @param clazz
 * @return returns stored struct
 */
private Map<Key, Array> store(Class clazz) {
    Method[] methods = clazz.getMethods();
    Map<Key, Array> methodsMap = new ConcurrentHashMap<Key, Array>();
    for (int i = 0; i < methods.length; i++) {
        storeMethod(methods[i], methodsMap);

    }
    map.put(clazz, methodsMap);
    return methodsMap;
}

From source file:org.mimacom.sample.integration.patterns.user.service.web.SimpleUserController.java

public SimpleUserController(SimpleSearchServiceIntegration simpleSearchServiceIntegration) {
    this.simpleSearchServiceIntegration = simpleSearchServiceIntegration;
    this.userRepository = new ConcurrentHashMap<>();
}

From source file:corner.cache.services.impl.local.LocalCacheImpl.java

@SuppressWarnings("unchecked")
private void init() {
    cache = new ConcurrentHashMap();

    expiryCache = new ConcurrentHashMap<String, Long>();

    scheduleService = Executors.newScheduledThreadPool(1);

    scheduleService.scheduleAtFixedRate(new CheckOutOfDateSchedule(cache, expiryCache), 0, expiryInterval * 60,
            TimeUnit.SECONDS);//from   w ww.j  a v  a  2s. com

    if (logger.isInfoEnabled())
        logger.info("DefaultCache CheckService is start!");
}

From source file:kr.co.bitnine.octopus.frame.SessionServer.java

@Override
protected void serviceInit(Configuration conf) throws Exception {
    super.serviceInit(conf);

    LOG.info("initialize service - " + getName());

    sessions = new ConcurrentHashMap<>();

    int sessMax = conf.getInt(OctopusConfiguration.MASTER_SESSION_MAX, EXECUTOR_MAX_DEFAULT);
    LOG.debug("create ThreadPoolExecutor for sessions (" + OctopusConfiguration.MASTER_SERVER_ADDRESS + '='
            + sessMax + ')');
    executor = new ThreadPoolExecutor(0, sessMax, EXECUTOR_KEEPALIVE_DEFAULT, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>());

    listener = new Listener();
    LOG.debug("thread " + listener.getName() + " is created");
}

From source file:com.baidu.rigel.biplatform.ma.report.query.QueryContext.java

/**
 * ??/*  w  w w .j  av a 2  s  . c o m*/
 * 
 * @param itemId
 * @param value
 */
public void put(String id, Object value) {

    if (this.params == null) {
        this.params = new ConcurrentHashMap<String, Object>();
    }
    if (StringUtils.isNotEmpty(id) && value != null) {
        this.params.put(id, value);
    }
}

From source file:com.vmware.o11n.plugin.powershell.model.impl.HostManagerImpl.java

public HostManagerImpl() {
    hosts = new ConcurrentHashMap<String, Host>();
}

From source file:au.org.ala.spatial.analysis.layers.LayerDistanceIndex.java

/**
 * Get all available inter layer association distances.
 *
 * @return Map of all available distances as Map&ltString, Double&gt. The
 * key String is fieldId1 + " " + fieldId2 where fieldId1 &lt fieldId2.
 *///from   ww w  .  j  av  a2s .co  m
static public Map<String, Double> loadDistances() {
    Map<String, Double> map = new ConcurrentHashMap<String, Double>();
    BufferedReader br = null;
    try {
        File file = new File(IntersectConfig.getAlaspatialOutputPath() + LAYER_DISTANCE_FILE);

        //attempt to create empty file if it does not exist
        if (!new File(IntersectConfig.getAlaspatialOutputPath()).exists()) {
            new File(IntersectConfig.getAlaspatialOutputPath()).mkdirs();
        }
        if (!file.exists()) {
            FileUtils.writeStringToFile(file, "");
        }
        br = new BufferedReader(new FileReader(file));

        String line;
        while ((line = br.readLine()) != null) {
            if (line.length() > 0) {
                String[] keyvalue = line.split("=");
                double d = Double.NaN;
                try {
                    d = Double.parseDouble(keyvalue[1]);
                } catch (Exception e) {
                    logger.info("cannot parse value in " + line);
                }
                map.put(keyvalue[0], d);
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }

    return map;
}

From source file:com.github.jknack.handlebars.cache.HighConcurrencyTemplateCache.java

/**
 * Creates a new HighConcurrencyTemplateCache.
 *//*from w w w .j  a va  2  s  . c  o  m*/
public HighConcurrencyTemplateCache() {
    this(new ConcurrentHashMap<TemplateSource, Future<Pair<TemplateSource, Template>>>());
}

From source file:com.openteach.diamond.network.waverider.WaveriderClient.java

@Override
public void initialize() {
    super.initialize();
    idGenerator = new AtomicLong(0);
    pendingRequestMap = new ConcurrentHashMap<String, PendingRequest>();
    slaveNode = WaveriderFactory.newInstance(config).buildSlave();
    slaveNode.addCommandHandler(COMMAND_DIAMOND_RESPONSE, new CommandHandler() {

        @Override/*  w w  w  . j a v a 2s .  c o  m*/
        public Command handle(Command command) {
            NetworkResponse response = NetworkResponse.unmarshall(command.getPayLoad());
            PendingRequest pr = pendingRequestMap.get(response.getId());
            if (null == pr) {
                logger.error(String.format(
                        "Server send response but there is no request for this response: % request id:%d",
                        response.getId()));
                return null;
            }
            pr.response = response;
            synchronized (pr.request) {
                pr.request.notifyAll();
            }
            return null;
        }

    });
    slaveNode.init();
    slaveNode.start();
}