当前位置: 首页>>代码示例>>Java>>正文


Java ConcurrentHashMap.put方法代码示例

本文整理汇总了Java中java.util.concurrent.ConcurrentHashMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentHashMap.put方法的具体用法?Java ConcurrentHashMap.put怎么用?Java ConcurrentHashMap.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ConcurrentHashMap的用法示例。


在下文中一共展示了ConcurrentHashMap.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: commandList

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Composes the list of commands and initialises them with the build graph.
 *
 *
 * @param logger
 * @param buildGraph
 * @param classPath
 * @param workspace
 * @return
 */
private ConcurrentHashMap<String, Command> commandList(final Tracer logger, final BuildGraph buildGraph, final ClassPath classPath, final Workspace workspace) {
    final ConcurrentHashMap<String, Command> commands = new ConcurrentHashMap<>();
    final ArrayList<Command> list = new ArrayList<>();

    final BuildCommand buildCommand = new BuildCommand(logger, buildGraph, classPath, workspace.getOutputDir());

    list.add(buildCommand);
    list.add(new PrintDepsCommand(logger, buildGraph));
    list.add(new ReplCommand(logger, buildGraph, classPath, buildCommand));
    list.add(new RunCommand(logger, buildGraph, classPath, buildCommand));
    list.add(new PrintTargetsCommand(logger, buildGraph));

    for (final Command c : list) {
        commands.put(c.getTarget(), c);
    }

    return commands;
}
 
开发者ID:nfisher,项目名称:cljbuck,代码行数:29,代码来源:Main.java

示例2: buildVocabulary

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
private ConcurrentHashMap<String, Integer> buildVocabulary(InputStream input) throws IOException {

		ConcurrentHashMap<String, Integer> vocabulary = new ConcurrentHashMap<>();

		try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) {
			String l = buffer.readLine();
			while (l != null ) {
				String p[] = l.split(",");
				if (p[1].length() > 1) {
					vocabulary.put(p[0], Integer.valueOf(p[1]));
				}
				l = buffer.readLine();
			}
		}
		return vocabulary;
	}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:tensorflow,代码行数:17,代码来源:WordVocabulary.java

示例3: findAllDevices

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
private ConcurrentHashMap<String,String> findAllDevices(){
	ConcurrentHashMap<String,String> devices = new ConcurrentHashMap<>();
	// Parse each driver
	Iterator<Driver> itdriv;
	try {
		itdriv = getDrivers().iterator();
		while(itdriv.hasNext()) {
			Driver driver = itdriv.next();
			for (File file : driver.getDevices()) {
				String deviceName = file.getName();
				String devicePath = file.getAbsolutePath();
				deviceName = String.format("%s (%s)", deviceName, driver.getName());
				Log.d("SerialPortFinder", "findAllDevices device name : " + deviceName + " , device path : " + devicePath);
				devices.put(deviceName, devicePath);
			}
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
	return devices;
}
 
开发者ID:HelloHuDi,项目名称:usb-with-serial-port,代码行数:22,代码来源:SerialPortFinder.java

示例4: getCloneForTransmission

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Retrieve a vector that can be sent to another member. This clones all of the version
 * information to protect against concurrent modification during serialization
 */
public RegionVersionVector<T> getCloneForTransmission() {
  Map<T, RegionVersionHolder<T>> liveHolders;
  liveHolders = new HashMap<T, RegionVersionHolder<T>>(this.memberToVersion);
  ConcurrentHashMap<T, RegionVersionHolder<T>> clonedHolders =
      new ConcurrentHashMap<T, RegionVersionHolder<T>>(liveHolders.size(), LOAD_FACTOR,
          CONCURRENCY_LEVEL);
  for (Map.Entry<T, RegionVersionHolder<T>> entry : liveHolders.entrySet()) {
    clonedHolders.put(entry.getKey(), entry.getValue().clone());
  }
  ConcurrentHashMap<T, Long> gcVersions = new ConcurrentHashMap<T, Long>(
      this.memberToGCVersion.size(), LOAD_FACTOR, CONCURRENCY_LEVEL);
  gcVersions.putAll(this.memberToGCVersion);
  RegionVersionHolder<T> clonedLocalHolder;
  clonedLocalHolder = this.localExceptions.clone();
  // Make sure the holder that we send to the peer does
  // have an accurate RegionVersionHolder for our local version
  return createCopy(this.myId, clonedHolders, this.localVersion.get(), gcVersions,
      this.localGCVersion.get(), false, clonedLocalHolder);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:24,代码来源:RegionVersionVector.java

示例5: testRegisterBroker

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
@Test
public void testRegisterBroker() {
    TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper();
    ConcurrentHashMap<String, TopicConfig> topicConfigConcurrentHashMap = new ConcurrentHashMap<>();
    TopicConfig topicConfig = new TopicConfig();
    topicConfig.setWriteQueueNums(8);
    topicConfig.setTopicName("unit-test");
    topicConfig.setPerm(6);
    topicConfig.setReadQueueNums(8);
    topicConfig.setOrder(false);
    topicConfigConcurrentHashMap.put("unit-test", topicConfig);
    topicConfigSerializeWrapper.setTopicConfigTable(topicConfigConcurrentHashMap);
    Channel channel = mock(Channel.class);
    RegisterBrokerResult registerBrokerResult = routeInfoManager.registerBroker("default-cluster", "127.0.0.1:10911", "default-broker", 1234, "127.0.0.1:1001",
        topicConfigSerializeWrapper, new ArrayList<String>(), channel);
    assertThat(registerBrokerResult).isNotNull();
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:18,代码来源:RouteInfoManagerTest.java

示例6: addListener

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Registers the non-static listener methods of a given object
 * @param listener the object
 */
public void addListener(Object listener) {

    try {
        for (Method method : listener.getClass().getDeclaredMethods()) {
            if (method.isAnnotationPresent(EventHandler.class)) {
                if (method.getParameterCount() == 1 && Event.class.isAssignableFrom(method.getParameters()[0].getType())) {
                    EventHandler annotation = method.getAnnotation(EventHandler.class);
                    ConcurrentHashMap<EventPrio, ArrayList<Listener>> listeners = eventListener.getOrDefault(method.getParameters()[0].getType().getName(), new ConcurrentHashMap<>());
                    ArrayList<Listener> methods = listeners.getOrDefault(annotation.prio(), new ArrayList<>());
                    method.setAccessible(true);
                    methods.add(new Listener(listener, method));
                    listeners.put(annotation.prio(), methods);
                    eventListener.put((method.getParameters()[0].getType().getName()), listeners);
                }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.addException(e);
    }
}
 
开发者ID:Zortax,项目名称:PraFramework,代码行数:25,代码来源:EventManager.java

示例7: main

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    final ConcurrentHashMap<String, String> concurrentHashMap =
        new ConcurrentHashMap<>();

    concurrentHashMap.put("One", "Un");
    concurrentHashMap.put("Two", "Deux");
    concurrentHashMap.put("Three", "Trois");

    Set<Map.Entry<String, String>> entrySet = concurrentHashMap.entrySet();
    HashSet<Map.Entry<String, String>> hashSet = new HashSet<>(entrySet);

    if (false == hashSet.equals(entrySet)) {
        throw new RuntimeException("Test FAILED: Sets are not equal.");
    }
    if (hashSet.hashCode() != entrySet.hashCode()) {
        throw new RuntimeException("Test FAILED: Set's hashcodes are not equal.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:DistinctEntrySetElements.java

示例8: main

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public static void main(String[] args) {
    ArrayList<String> list = new ArrayList<>(Arrays.asList("I", "love", "you", "too"));

    list.removeIf(new Predicate<String>() {
        @Override
        public boolean test(String s) {
            if (s.length() < 2) {

                return true;
            }
            return false;
        }
    });
    list.removeIf(l -> l.length() < 4);
    System.out.println(JSON.toJSONString(list));
    Date date = new Date();

    ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap<>();
    concurrentHashMap.put("ds", 1);
    concurrentHashMap.computeIfAbsent("fdfd", k -> k.toString());
    System.out.println(JSON.toJSONString(concurrentHashMap));
    HashMap hashMap = new HashMap<>();
    hashMap.put("fd1", 1);
    hashMap.put("fd2", 1);
    hashMap.put("fd3", 1);
    hashMap.put("fd4", "fd");
    hashMap.put("fd5", 1);
    hashMap.entrySet().stream().forEach(hash -> {
        System.out.println(hash.toString());
    });
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:32,代码来源:WashMap.java

示例9: updateReplicaReassignmentTimestamp

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public static void updateReplicaReassignmentTimestamp(String brokerZkUrl,
                                                       ReplicaStat replicaStat) {
  if (!replicaReassignmentTimestamps.containsKey(brokerZkUrl)) {
    replicaReassignmentTimestamps.put(brokerZkUrl, new ConcurrentHashMap<>());
  }
  ConcurrentHashMap<TopicPartition, Long> replicaTimestamps =
      replicaReassignmentTimestamps.get(brokerZkUrl);
  TopicPartition topicPartition = new TopicPartition(
      replicaStat.getTopic(), replicaStat.getPartition());

  if (!replicaTimestamps.containsKey(topicPartition) ||
      replicaTimestamps.get(topicPartition) < replicaStat.getTimestamp()) {
    replicaTimestamps.put(topicPartition, replicaStat.getTimestamp());
  }
}
 
开发者ID:pinterest,项目名称:doctorkafka,代码行数:16,代码来源:ReplicaStatsManager.java

示例10: testPut1_NullPointerException

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * put(null,x) throws NPE
 */
public void testPut1_NullPointerException() {
    ConcurrentHashMap c = new ConcurrentHashMap(5);
    try {
        c.put(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ConcurrentHashMapTest.java

示例11: testRemove1_NullPointerException

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * remove(null) throws NPE
 */
public void testRemove1_NullPointerException() {
    ConcurrentHashMap c = new ConcurrentHashMap(5);
    c.put("sadsdf", "asdads");
    try {
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ConcurrentHashMapTest.java

示例12: buildJdbcJavaClassMappings

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
private static ConcurrentHashMap<Class, Integer> buildJdbcJavaClassMappings() {
	ConcurrentHashMap<Class, Integer> jdbcJavaClassMappings = new ConcurrentHashMap<Class, Integer>();

	// these mappings are the ones outlined specifically in the spec
	jdbcJavaClassMappings.put( String.class, Types.VARCHAR );
	jdbcJavaClassMappings.put( BigDecimal.class, Types.NUMERIC );
	jdbcJavaClassMappings.put( Boolean.class, Types.BIT );
	jdbcJavaClassMappings.put( Integer.class, Types.INTEGER );
	jdbcJavaClassMappings.put( Long.class, Types.BIGINT );
	jdbcJavaClassMappings.put( Float.class, Types.REAL );
	jdbcJavaClassMappings.put( Double.class, Types.DOUBLE );
	jdbcJavaClassMappings.put( byte[].class, Types.LONGVARBINARY );
	jdbcJavaClassMappings.put( java.sql.Date.class, Types.DATE );
	jdbcJavaClassMappings.put( Time.class, Types.TIME );
	jdbcJavaClassMappings.put( Timestamp.class, Types.TIMESTAMP );
	jdbcJavaClassMappings.put( Blob.class, Types.BLOB );
	jdbcJavaClassMappings.put( Clob.class, Types.CLOB );
	jdbcJavaClassMappings.put( Array.class, Types.ARRAY );
	jdbcJavaClassMappings.put( Struct.class, Types.STRUCT );
	jdbcJavaClassMappings.put( Ref.class, Types.REF );
	jdbcJavaClassMappings.put( Class.class, Types.JAVA_OBJECT );

	// additional "common sense" registrations
	jdbcJavaClassMappings.put( Character.class, Types.CHAR );
	jdbcJavaClassMappings.put( char[].class, Types.VARCHAR );
	jdbcJavaClassMappings.put( Character[].class, Types.VARCHAR );
	jdbcJavaClassMappings.put( Byte[].class, Types.LONGVARBINARY );
	jdbcJavaClassMappings.put( java.util.Date.class, Types.TIMESTAMP );
	jdbcJavaClassMappings.put( Calendar.class, Types.TIMESTAMP );

	return jdbcJavaClassMappings;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:JdbcTypeJavaClassMappings.java

示例13: concurrentHashMapCopy

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
@Benchmark
public ConcurrentHashMap concurrentHashMapCopy(Context context) { //Populates a map, then copies it
	ConcurrentHashMap<Long, Object> map = new ConcurrentHashMap<>();
	
	//Populate the map the first time
	for (int i = 0; i < context.testValues.length; i++)
		map.put(context.testKeys[i], context.testValues[i]);
	
	//Copy!
	ConcurrentHashMap<Long, Object> copy = new ConcurrentHashMap<>(map);
	return copy;
}
 
开发者ID:austinv11,项目名称:Long-Map-Benchmarks,代码行数:13,代码来源:MapTests.java

示例14: recieve

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
@Hidden
public void recieve(int port,int paramBufferSize,int maxFileSize) {
    ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
    serverSocketChannel.socket().bind(new InetSocketAddress(port));
    ByteBuffer parameters = ByteBuffer.allocate(paramBufferSize);
    ByteBuffer content = ByteBuffer.allocate(maxFileSize);
    CharBuffer buffer = CharBuffer.allocate(paramBufferSize);
    List < ScheduledFuture > futures = new ArrayList < ScheduledFuture > ();
    ExecutorService executorService = Executors.newFixedThreadPool(maxAgents);
    int currentConnections;
    Method[] methods=servlet.class.getDeclaredMethods();
    List<String> methodNames=new ArrayList<String>();
    ConcurrentHashMap<String,Method> hashMap=new ConcurrentHashMap<String,Method>();
    SocketChannel[] sections;
    for(Method method:methods){
        Annotation[] annotations=method.getAnnotations();
        if(Arrays.asList(annotations).contains(Hidden.class)){
            continue;
        }
        else{
        hashMap.put(method.getName(),method);
        methodNames.add(method.getName());
        }
    }
    Runnable serverThread = () -> {
       /* socketChannel.read(parameters);
        if (params[0].equals("put")) {
            socketChannel.read(content);
            
        }
        buffer = buff.asCharBuffer();
        String str = buffer.toString();
        String[] params = str.split(":");
        if (params[0].equals("put")) {       
            java.nio.file.Path p = Paths.get(tempPath + params[2]);
            Files.write(p, content.array());
            this.put(params);
            Files.delete(p);
        } else if (params[0].equals("get")) {
            ByteBuffer b = this.get(params);
            socketChannel.write(b);
        } else if (params[0].equals("remove")) {
            this.remove(params);
        }
        futures.remove(i);*/
        
    };
    while (acceptingConnections) {
        socketChannel[0] = serverSocketChannel.accept();
        if (socketChannel != null) {
            ScheduledFuture future = executorService.submit(serverThread);
            i = futures.size();
            futures.add(future);
        }
    }
}
 
开发者ID:EventHorizon27,项目名称:dataset-lib,代码行数:57,代码来源:AppServer.java

示例15: search

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Searches for a token within the index
 * @param token the token
 * @return a mapping between the found token and document IDs
 */
public ConcurrentHashMap<String, ConcurrentHashMap<Integer, Double>> search(String token) {
    ConcurrentHashMap<String, ConcurrentHashMap<Integer, Double>> mapping = new ConcurrentHashMap<>();

    int level = checkSplitLevel(token);

    if (tmap_cache.entrySet().stream().sequential().noneMatch(entry -> entry.getKey().equals(token.substring(0, level)))) {
        //tmap not loaded - we need to load the correspondent map to search for matching docIDs
        String l_idx = token.substring(0, level);
        File toLoad = new File(dirname + "/" + l_idx + ".termMap.master");

        if (!toLoad.exists()) {
            //the token we are searching for is not mapped in disk, so we return an empty map
            return mapping;
        }
        long fileSize = toLoad.length();

        double used = mem.getUsedPer();
        double max = mem.getMaxMem();
        long fSizeMB = MemUtil.toMB(fileSize);
        double inflateRate = 2.0;
        double inflated = fSizeMB * inflateRate / max;
        double toCompare = used + inflated;

        while (toCompare >= 0.60 && !tmap_cache.isEmpty()) {
            timeOutTMap();
            System.runFinalization();
            System.gc();
        }
        loadTMap(l_idx, toLoad.getAbsolutePath());
    }

    //list of doc IDs where the term occurs
    //retrieve the token termMap
    ConcurrentHashMap<Integer, Double> docIDs = tmap_cache.get(token.substring(0, level))
            .getRight()
            .getTmap()
            .get(token);

    if (docIDs == null) {
        //the token we are searching for is not mapped in memory, so we return an empty map
        return mapping;
    }

    //update the timestamp
    tmap_cache.get(token.substring(0, level))
            .setLeft(System.currentTimeMillis());

    //insert said list into a mapping data structure
    mapping.put(token, docIDs);

    return mapping;
}
 
开发者ID:luminoso,项目名称:information-retrieval,代码行数:58,代码来源:SearchEngine.java


注:本文中的java.util.concurrent.ConcurrentHashMap.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。