List of usage examples for java.util.concurrent ConcurrentHashMap put
public V put(K key, V value)
From source file:Main.java
public static void main(final String[] args) { ConcurrentHashMap<Integer, UUID> concurrentHashMap = new ConcurrentHashMap<>(); for (int i = 0; i < 100; i++) { concurrentHashMap.put(i, UUID.randomUUID()); }/*from w w w .ja v a2 s . c o m*/ int threshold = 1; concurrentHashMap.forEachValue(threshold, System.out::println); concurrentHashMap.forEach((id, uuid) -> { if (id % 10 == 0) { System.out.println(String.format("%s: %s", id, uuid)); } }); String searchResult = concurrentHashMap.search(threshold, (id, uuid) -> { if (String.valueOf(uuid).contains(String.valueOf(id))) { return new String(id + ":" + uuid); } return null; }); System.out.println(searchResult); }
From source file:org.jumpmind.metl.Develop.java
public static void main(String[] args) throws Exception { System.out/*from w w w . j a v a 2 s. com*/ .println(IOUtils.toString(new FileInputStream("../metl-server/src/main/resources/Metl.asciiart"))); new File("working").mkdirs(); System.setProperty("org.jumpmind.metl.ui.init.config.dir", "working"); Server server = new Server(42000); ClassList classlist = Configuration.ClassList.setServerDefault(server); classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration"); WebAppContext webapp = new WebAppContext(); webapp.setParentLoaderPriority(true); webapp.setConfigurationDiscovered(true); webapp.setContextPath("/metl"); webapp.setWar("src/main/webapp"); webapp.setResourceBase("src/main/webapp"); ConcurrentHashMap<String, ConcurrentHashSet<String>> map = new ClassInheritanceMap(); ConcurrentHashSet<String> set = new ConcurrentHashSet<>(); set.add("org.jumpmind.metl.ui.init.AppInitializer"); map.put("org.springframework.web.WebApplicationInitializer", set); webapp.setAttribute(AnnotationConfiguration.CLASS_INHERITANCE_MAP, map); server.setHandler(webapp); ServerContainer webSocketServer = WebSocketServerContainerInitializer.configureContext(webapp); webSocketServer.setDefaultMaxSessionIdleTimeout(10000000); server.start(); server.join(); }
From source file:in.sc.dao.ListGenerator.java
public static void main(String[] args) { ListGenerator li = new ListGenerator(); // ProductHelper li1 = new ProductHelper(); // li.getListsDetails(13); // ArrayList<ProductBean> data = (ArrayList) li1.getProductLists1(pb.getFilterMap()); // li1.insertListProductMap(data, 3); int cnt = 0;//from ww w . j a v a2 s. c o m // for (Object o : data) { // System.out.println("" + o); // // cnt++; // } li.generateCat(0); ConcurrentHashMap cfm = new ConcurrentHashMap(); HashMap hm = new HashMap(); cfm.put("1", cnt); cfm.put("2", cnt); cfm.put(5, cnt); cfm.put(3, cnt); // System.out.println("count " + cnt); }
From source file:Main.java
public static <KEY, VALUE> ConcurrentHashMap<KEY, VALUE> newConcurrentHashMap(KEY key, VALUE value) { final ConcurrentHashMap<KEY, VALUE> map = newConcurrentHashMapSized(1); map.put(key, value); return map;// w ww . ja v a2 s. c om }
From source file:Main.java
public static <KEY, VALUE> ConcurrentHashMap<KEY, VALUE> newConcurrentHashMap(KEY key1, VALUE value1, KEY key2, VALUE value2) {//from ww w.ja v a 2s.co m final ConcurrentHashMap<KEY, VALUE> map = newConcurrentHashMapSized(2); map.put(key1, value1); map.put(key2, value2); return map; }
From source file:com.jayway.restassured.examples.springmvc.support.WithJetty.java
@BeforeClass public static void startJetty() throws Exception { server = new Server(8080); Connector connector = new ServerConnector(server); server.addConnector(connector);/*from w ww . j ava 2s . c om*/ WebAppContext wac = new WebAppContext(); wac.setContextPath("/"); wac.setConfigurations(new Configuration[] { new WebXmlConfiguration(), new AnnotationConfiguration() { @Override public void preConfigure(WebAppContext context) throws Exception { ConcurrentHashMap<String, ConcurrentHashSet<String>> map = new ConcurrentHashMap<String, ConcurrentHashSet<String>>(); ConcurrentHashSet<String> set = new ConcurrentHashSet<String>(); set.add(WebApp.class.getName()); map.put(WebApplicationInitializer.class.getName(), set); context.setAttribute(CLASS_INHERITANCE_MAP, map); _classInheritanceHandler = new ClassInheritanceHandler(map); } } }); wac.setServer(server); server.setHandler(wac); server.start(); }
From source file:com.clustercontrol.repository.factory.NodeProperty.java
public static void init() { JpaTransactionManager jtm = null;//w w w. j av a 2 s.co m try { _lock.writeLock(); long startTime = System.currentTimeMillis(); jtm = new JpaTransactionManager(); jtm.getEntityManager().clear(); ConcurrentHashMap<String, NodeInfo> cache = new ConcurrentHashMap<String, NodeInfo>(); for (NodeInfo node : QueryUtil.getAllNode_NONE()) { cache.put(node.getFacilityId(), node); } storeCache(cache); m_log.info("init cache " + (System.currentTimeMillis() - startTime) + "ms. size=" + cache.size()); } finally { if (jtm != null) { jtm.close(); } _lock.writeUnlock(); } }
From source file:com.clustercontrol.repository.factory.NodeProperty.java
public static void updateNode(String facilityId) { m_log.info("update NodeCache : " + facilityId); try {//from ww w . j a va2 s.co m _lock.writeLock(); ConcurrentHashMap<String, NodeInfo> cache = getCache(); try { new JpaTransactionManager().getEntityManager().clear(); NodeInfo facilityEntity = QueryUtil.getNodePK(facilityId); cache.put(facilityId, facilityEntity); } catch (Exception e) { m_log.warn("update NodeCache failed : " + e.getMessage()); //?????????? cache.remove(facilityId); } storeCache(cache); } finally { _lock.writeUnlock(); } }
From source file:org.wso2.carbon.mediator.cache.util.HttpCachingFilter.java
/** * This method returns whether no-store header exists in the response. * * @param msgCtx MessageContext with the transport headers. * @return Whether no-store exists or not. */// w ww . j a v a 2s . c o m @SuppressWarnings("unchecked") public static boolean isNoStore(org.apache.axis2.context.MessageContext msgCtx) { ConcurrentHashMap<String, Object> headerProperties = new ConcurrentHashMap<>(); Map<String, String> headers = (Map<String, String>) msgCtx .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); String cacheControlHeaderValue = null; //Copying All TRANSPORT_HEADERS to headerProperties Map. for (Map.Entry<String, String> entry : headers.entrySet()) { headerProperties.put(entry.getKey(), entry.getValue()); } if (headerProperties.get(HttpHeaders.CACHE_CONTROL) != null) { cacheControlHeaderValue = String.valueOf(headerProperties.get(HttpHeaders.CACHE_CONTROL)); } return StringUtils.isNotEmpty(cacheControlHeaderValue) && cacheControlHeaderValue.contains(CachingConstants.NO_STORE_STRING); }
From source file:com.clustercontrol.repository.factory.NodeProperty.java
/** * ??ID???????<BR>//from w w w .j av a 2 s .co m * * @param facilityId ID * @param mode ???? * @return * @throws FacilityNotFound */ public static NodeInfo getProperty(String facilityId) throws FacilityNotFound { m_log.debug("getProperty() : facilityId = " + facilityId); if (facilityId == null || facilityId.compareTo("") == 0) { return new NodeInfo(); } { // ????????????????????????? // (ConcurrentHashMap???????????????) ConcurrentHashMap<String, NodeInfo> cache = getCache(); NodeInfo nodeInfo = cache.get(facilityId); if (nodeInfo != null) { if (!facilityId.equals(nodeInfo.getFacilityId())) { // ?????????????? m_log.error("cache is broken." + facilityId + "," + nodeInfo.getFacilityId()); } return nodeInfo; } } try { _lock.writeLock(); ConcurrentHashMap<String, NodeInfo> cache = getCache(); NodeInfo facilityEntity = QueryUtil.getNodePK(facilityId); cache.put(facilityId, facilityEntity); storeCache(cache); return facilityEntity; } finally { _lock.writeUnlock(); } }