java.util.concurrent.ConcurrentHashMap#size ( )源码实例Demo

下面列出了java.util.concurrent.ConcurrentHashMap#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Tomcat8-Source-Read   文件: SlowQueryReport.java
protected QueryStats getQueryStats(String sql) {
    if (sql==null) sql = "";
    ConcurrentHashMap<String,QueryStats> queries = SlowQueryReport.this.queries;
    if (queries==null) {
        if (log.isWarnEnabled()) log.warn("Connection has already been closed or abandoned");
        return null;
    }
    QueryStats qs = queries.get(sql);
    if (qs == null) {
        qs = new QueryStats(sql);
        if (queries.putIfAbsent(sql,qs)!=null) {
            qs = queries.get(sql);
        } else {
            //we added a new element, see if we need to remove the oldest
            if (queries.size() > maxQueries) {
                removeOldest(queries);
            }
        }
    }
    return qs;
}
 
源代码2 项目: hollow   文件: AbstractHollowProducer.java
HollowProducer.Populator incrementalPopulate(
        ProducerListeners listeners,
        HollowProducer.Incremental.IncrementalPopulator incrementalPopulator,
        long toVersion) throws Exception {
    ConcurrentHashMap<RecordPrimaryKey, Object> events = new ConcurrentHashMap<>();
    Status.IncrementalPopulateBuilder incrementalPopulateStatus = listeners.fireIncrementalPopulateStart(toVersion);
    try (CloseableIncrementalWriteState iws = new CloseableIncrementalWriteState(events, getObjectMapper())) {
        incrementalPopulator.populate(iws);
        incrementalPopulateStatus.success();

        long removed = events.values().stream()
                .filter(o -> o == HollowIncrementalCyclePopulator.DELETE_RECORD).count();
        long addedOrModified = events.size() - removed;
        incrementalPopulateStatus.changes(removed, addedOrModified);
    } catch (Throwable th) {
        incrementalPopulateStatus.fail(th);
        throw th;
    } finally {
        listeners.fireIncrementalPopulateComplete(incrementalPopulateStatus);
    }

    return new HollowIncrementalCyclePopulator(events, 1.0);
}
 
源代码3 项目: carina   文件: DriverPoolTest.java
/**
 * Register driver in the DriverPool with device
 * 
 * @param driver
 *            WebDriver
 * @param name
 *            String driver name
 * @param device
 *            Device
 * 
 */
private void registerDriver(WebDriver driver, String name, Device device) {
    Long threadId = Thread.currentThread().getId();
    ConcurrentHashMap<String, CarinaDriver> currentDrivers = getDrivers();

    int maxDriverCount = Configuration.getInt(Parameter.MAX_DRIVER_COUNT);

    if (currentDrivers.size() == maxDriverCount) {
        Assert.fail("Unable to register driver as you reached max number of drivers per thread: " + maxDriverCount);
    }
    if (currentDrivers.containsKey(name)) {
        Assert.fail("Driver '" + name + "' is already registered for thread: " + threadId);
    }

    // new 6.0 approach to manipulate drivers via regular Set
    CarinaDriver carinaDriver = new CarinaDriver(name, driver, device, TestPhase.getActivePhase(), threadId);
    driversPool.add(carinaDriver);
}
 
源代码4 项目: StatsAgg   文件: StatsdAggregationThread.java
private List<StatsdMetric> getCurrentStatsdMetricsAndRemoveMetricsFromGlobal(ConcurrentHashMap<Long,StatsdMetric> statsdMetrics) {

        if (statsdMetrics == null) {
            return new ArrayList();
        }

        List<StatsdMetric> statsdMetricsToReturn = new ArrayList(statsdMetrics.size());
        
        for (StatsdMetric statsdMetric : statsdMetrics.values()) {
            if (statsdMetric.getMetricReceivedTimestampInMilliseconds() <= threadStartTimestampInMilliseconds_) {
                statsdMetricsToReturn.add(statsdMetric);
                statsdMetrics.remove(statsdMetric.getHashKey());
            }
        }

        return statsdMetricsToReturn;
    }
 
源代码5 项目: tomcatsrc   文件: SlowQueryReport.java
protected QueryStats getQueryStats(String sql) {
    if (sql==null) sql = "";
    ConcurrentHashMap<String,QueryStats> queries = SlowQueryReport.this.queries;
    if (queries==null) {
        if (log.isWarnEnabled()) log.warn("Connection has already been closed or abandoned");
        return null;
    }
    QueryStats qs = queries.get(sql);
    if (qs == null) {
        qs = new QueryStats(sql);
        if (queries.putIfAbsent(sql,qs)!=null) {
            qs = queries.get(sql);
        } else {
            //we added a new element, see if we need to remove the oldest
            if (queries.size() > maxQueries) {
                removeOldest(queries);
            }
        }
    }
    return qs;
}
 
源代码6 项目: Tomcat8-Source-Read   文件: SlowQueryReport.java
/**
 * Sort QueryStats by last invocation time
 * @param queries The queries map
 */
protected void removeOldest(ConcurrentHashMap<String,QueryStats> queries) {
    ArrayList<QueryStats> list = new ArrayList<>(queries.values());
    Collections.sort(list, queryStatsComparator);
    int removeIndex = 0;
    while (queries.size() > maxQueries) {
        String sql = list.get(removeIndex).getQuery();
        queries.remove(sql);
        if (log.isDebugEnabled()) log.debug("Removing slow query, capacity reached:"+sql);
        removeIndex++;
    }
}
 
源代码7 项目: openjdk-jdk9   文件: CleanerTest.java
/**
 * Example using a Cleaner to remove WeakKey references from a Map.
 */
@Test
void testWeakKey() {
    ConcurrentHashMap<WeakKey<String>, String> map = new ConcurrentHashMap<>();
    Cleaner cleaner = Cleaner.create();
    String key = new String("foo");  //  ensure it is not interned
    String data = "bar";

    map.put(new WeakKey<>(key, cleaner, map), data);

    WeakKey<String> k2 = new WeakKey<>(key, cleaner, map);

    Assert.assertEquals(map.get(k2), data, "value should be found in the map");
    key = null;
    System.gc();
    Assert.assertNotEquals(map.get(k2), data, "value should not be found in the map");

    final long CYCLE_MAX = Utils.adjustTimeout(30L);
    for (int i = 1; map.size() > 0 && i < CYCLE_MAX; i++) {
        map.forEach( (k, v) -> System.out.printf("    k: %s, v: %s%n", k, v));
        try {
            Thread.sleep(10L);
        } catch (InterruptedException ie) {}
    }
    Assert.assertEquals(map.size(), 0, "Expected map to be empty;");
    cleaner = null;
}
 
源代码8 项目: openjdk-jdk9   文件: HelloImpl.java
@Override
public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap)
        throws RemoteException {
    int hashMapSize = 0;

    hashMapSize = receivedHashMap.size();
    String response = "Hello with hashMapSize == " + hashMapSize;
    return response;
}
 
源代码9 项目: NYBus   文件: NYBusDriver.java
/**
 * Remove the event.
 *
 * @param mTargetMap               the target map.
 * @param mEventsToTargetsMapEntry the event to target map entry.
 */
private void removeEventIfRequired(ConcurrentHashMap<Object,
        ConcurrentHashMap<String, SubscriberHolder>> mTargetMap,
                                   Map.Entry<Class<?>, ConcurrentHashMap<Object,
                                           ConcurrentHashMap<String,
                                                   SubscriberHolder>>> mEventsToTargetsMapEntry) {
    if (mTargetMap.size() == 0) {
        mEventsToTargetsMap.remove(mEventsToTargetsMapEntry.getKey());
    }
}
 
public int size() {
    if (k1_k2V_map.size() == 0) return 0;

    int result = 0;
    for (ConcurrentHashMap<K2, V> k2V_map : k1_k2V_map.values()) {
        result += k2V_map.size();
    }
    return result;
}
 
源代码11 项目: pentaho-kettle   文件: LoggingRegistry.java
/**
 * Helper Method that determines a LogChannelFileWriterBuffer invoked by getLogChannelFileWriterBuffer and returns 1.
 * @param possibleWriters  Map to search from.
 * @return LogChannelFileWriterBuffer, null if could not be determined.
 */
private LogChannelFileWriterBuffer determineLogChannelFileWriterBuffer( ConcurrentHashMap<LogChannelFileWriterBuffer,
  List<String>> possibleWriters ) {

  // Just one writer so just return it
  if ( possibleWriters.size() == 1 ) {
    return possibleWriters.keys().nextElement();
  } else {

    // Several possibilities, so, lets get the writer among them that is the "lowest in the chain",
    // meaning, the one that is not a parent of the others
    Enumeration<LogChannelFileWriterBuffer> possibleWritersIds = possibleWriters.keys();
    while ( possibleWritersIds.hasMoreElements() ) {
      LogChannelFileWriterBuffer writer = possibleWritersIds.nextElement();

      for ( Map.Entry<LogChannelFileWriterBuffer, List<String>> entry : possibleWriters.entrySet() ) {
        if ( entry.getKey().equals( writer ) ) {
          continue;
        }
        if ( !entry.getValue().contains( writer.getLogChannelId() ) ) {
          return entry.getKey();
        }
      }
    }
  }

  return null;
}
 
源代码12 项目: dragonwell8_jdk   文件: HelloImpl.java
@Override
public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap)
        throws RemoteException {
    int hashMapSize = 0;

    hashMapSize = receivedHashMap.size();
    String response = "Hello with hashMapSize == " + hashMapSize;
    return response;
}
 
源代码13 项目: TencentKona-8   文件: HelloImpl.java
@Override
public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap)
        throws RemoteException {
    int hashMapSize = 0;

    hashMapSize = receivedHashMap.size();
    String response = "Hello with hashMapSize == " + hashMapSize;
    return response;
}
 
源代码14 项目: jdk8u60   文件: HelloImpl.java
@Override
public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap)
        throws RemoteException {
    int hashMapSize = 0;

    hashMapSize = receivedHashMap.size();
    String response = "Hello with hashMapSize == " + hashMapSize;
    return response;
}
 
源代码15 项目: gemfirexd-oss   文件: ProcedureResultCollector.java
/***
 * 
 * @param resultSetNumber
 * @return
 */
public IncomingResultSet[] getIncomingResultSets(int resultSetNumber) {
  IncomingResultSet[] retValue = null;
  Integer key = Integer.valueOf(resultSetNumber);
  if (this.incomingResultSets.containsKey(key)) {
    ConcurrentHashMap<String, IncomingResultSetImpl> sameNumberResultSets =
      this.incomingResultSets.get(key);
    retValue = new IncomingResultSet[sameNumberResultSets.size()];
    retValue = sameNumberResultSets.values().toArray(retValue);
  }
  return retValue;
}
 
源代码16 项目: hottub   文件: HelloImpl.java
@Override
public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap)
        throws RemoteException {
    int hashMapSize = 0;

    hashMapSize = receivedHashMap.size();
    String response = "Hello with hashMapSize == " + hashMapSize;
    return response;
}
 
源代码17 项目: gemfirexd-oss   文件: ProcedureResultCollector.java
/***
 * 
 * @param resultSetNumber
 * @return
 */
public IncomingResultSet[] getIncomingResultSets(int resultSetNumber) {
  IncomingResultSet[] retValue = null;
  Integer key = Integer.valueOf(resultSetNumber);
  if (this.incomingResultSets.containsKey(key)) {
    ConcurrentHashMap<String, IncomingResultSetImpl> sameNumberResultSets =
      this.incomingResultSets.get(key);
    retValue = new IncomingResultSet[sameNumberResultSets.size()];
    retValue = sameNumberResultSets.values().toArray(retValue);
  }
  return retValue;
}
 
源代码18 项目: Tomcat8-Source-Read   文件: StatementCache.java
@Override
public int getCacheSizePerConnection() {
    ConcurrentHashMap<CacheKey,CachedStatement> cache = getCache();
    if (cache == null) return 0;
    return cache.size();
}
 
private static int size(ManagedConcurrentValueMap<String, Object> map) {
    MetaClass metaClass = InvokerHelper.getMetaClass(map);
    ConcurrentHashMap<String, Object> internalMap = (ConcurrentHashMap<String, Object>)metaClass.getProperty(map, "internalMap");
    return internalMap.size();
}
 
源代码20 项目: OSPREY3   文件: KSAbstract.java
protected ConcurrentHashMap<Integer, PFAbstract> createPFs4Seqs(ArrayList<ArrayList<String>> seqs, 
		ArrayList<Boolean> contSCFlexVals, ArrayList<String> pfImplVals) {

	ConcurrentHashMap<Integer, PFAbstract> ans = new ConcurrentHashMap<>();

	ArrayList<Integer> strands = new ArrayList<Integer>(Arrays.asList(2, 0, 1));
	ArrayList<Integer> indexes = new ArrayList<>();
	for(int i = 0; i < strands.size(); i++) indexes.add(i);

	//indexes.parallelStream().forEach((index) -> {
	for(int index = 0; index < strands.size(); ++index) {

		int strand = strands.get(index);
		boolean contSCFlex = contSCFlexVals.get(strand);
		String pfImpl = pfImplVals.get(strand);
		ArrayList<String> seq = seqs.get(strand);

		PFAbstract pf = createPF4Seq(contSCFlex, strand, seq, pfImpl);

		// put partition function in global map
		name2PF.put(pf.getReducedSearchProblemName(), pf);

		// put in local map
		ans.put(strand, pf);

		// only continue if we have not already started computed the PF
		if( pf.getRunState() == RunState.NOTSTARTED ) {

			// get energy matrix
			if(pf.getReducedSearchProblem().getEnergyMatrix() == null) {
				pf.getReducedSearchProblem().loadEnergyMatrix();
			}

			// re-prune, since we have fewer witnesses now that we have trimmed the emat?
			// type dependent pruning doesn't take care of this?

			if(pf.getReducedSearchProblem().numConfs(pf.getReducedPruningMatrix()).compareTo(BigInteger.ZERO) == 0) {
				// no conformations in search space, so this cannot give a valid
				// partition function
				
				System.out.println("\nRe-pruning to steric threshold...");
				double maxPruningInterval = cfp.params.getDouble("StericThresh");
				pf.rePruneReducedSP(maxPruningInterval);
				
				if(pf.getReducedSearchProblem().numConfs(pf.getReducedPruningMatrix()).compareTo(BigInteger.ZERO) == 0) {
					
					System.out.println("\nWARNING: there are no valid conformations for sequence " + 
							KSAbstract.list1D2String(pf.getSequence(), " ") + " " + pf.getFlexibility() + "\n");
					
					pf.setEpsilonStatus(EApproxReached.NOT_POSSIBLE);
				}
			}

			// initialize conf counts for K*
			pf.setNumUnPruned();
			pf.setNumPruned();
		}
	}
	//});

	if(ans.size() != 3)
		throw new RuntimeException("ERROR: returned map must contain three different partition functions");

	return ans;
}