com.google.common.collect.Maps.newConcurrentMap()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(334)

本文整理了Java中com.google.common.collect.Maps.newConcurrentMap()方法的一些代码示例,展示了Maps.newConcurrentMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Maps.newConcurrentMap()方法的具体详情如下:
包路径:com.google.common.collect.Maps
类名称:Maps
方法名:newConcurrentMap

Maps.newConcurrentMap介绍

[英]Returns a general-purpose instance of ConcurrentMap, which supports all optional operations of the ConcurrentMap interface. It does not permit null keys or values. It is serializable.

This is currently accomplished by calling MapMaker#makeMap().

It is preferable to use MapMaker directly (rather than through this method), as it presents numerous useful configuration options, such as the concurrency level, load factor, key/value reference types, and value computation.
[中]返回ConcurrentMap的通用实例,该实例支持ConcurrentMap接口的所有可选操作。它不允许空键或值。它是可序列化的。
这目前是通过调用MapMaker#makeMap()实现的。
最好直接使用MapMaker(而不是通过这种方法),因为它提供了许多有用的配置选项,例如并发级别、负载因子、键/值引用类型和值计算。

代码示例

代码示例来源:origin: ctripcorp/apollo

public PortalDBPropertySource() {
 super("DBConfig", Maps.newConcurrentMap());
}

代码示例来源:origin: ctripcorp/apollo

public BizDBPropertySource() {
 super("DBConfig", Maps.newConcurrentMap());
}

代码示例来源:origin: spotify/helios

@Override
 public ConcurrentMap<JobId, Deque<TaskStatusEvent>> get() {
  return Maps.newConcurrentMap();
 }
});

代码示例来源:origin: apache/kylin

/**
 * Create a new {@link DefaultMetricCollector}.
 *
 * Note that when this constructor is called, the reporter is also
 * automatically established.
 */
public MemcachedMetrics() {
  counters = Maps.newConcurrentMap();
  meters = Maps.newConcurrentMap();
  histograms = Maps.newConcurrentMap();
}

代码示例来源:origin: google/guava

@Generates
private static <K, V> ConcurrentMap<K, V> generateConcurrentMap(K key, V value) {
 ConcurrentMap<K, V> map = Maps.newConcurrentMap();
 map.put(key, value);
 return map;
}

代码示例来源:origin: google/guava

@Empty
private static <K, V> ConcurrentMap<K, V> generateConcurrentMap() {
 return Maps.newConcurrentMap();
}

代码示例来源:origin: apache/incubator-gobblin

@VisibleForTesting
PortUtils(PortLocator locator) {
 this.portLocator = locator;
 this.assignedPorts = Maps.newConcurrentMap();
}

代码示例来源:origin: ctripcorp/apollo

private void initialize() {
 maxIdScanned = 0;
 publicAppNamespaceCache = new CaseInsensitiveMapWrapper<>(Maps.newConcurrentMap());
 appNamespaceCache = new CaseInsensitiveMapWrapper<>(Maps.newConcurrentMap());
 appNamespaceIdCache = Maps.newConcurrentMap();
 scheduledExecutorService = Executors.newScheduledThreadPool(1, ApolloThreadFactory
   .create("AppNamespaceServiceWithCache", true));
}

代码示例来源:origin: ctripcorp/apollo

public AbstractConfig() {
 m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
 m_configVersion = new AtomicLong();
 m_arrayCache = Maps.newConcurrentMap();
 allCaches = Lists.newArrayList();
}

代码示例来源:origin: ctripcorp/apollo

private void initialize() {
 releaseMessageCache = Maps.newConcurrentMap();
 doScan = new AtomicBoolean(true);
 executorService = Executors.newSingleThreadExecutor(ApolloThreadFactory
   .create("ReleaseMessageServiceWithCache", true));
}

代码示例来源:origin: Graylog2/graylog2-server

@Inject
public WidgetResultCache(MetricRegistry metricRegistry, WidgetStrategyFactory widgetStrategyFactory) {
  this.metricRegistry = metricRegistry;
  this.widgetStrategyFactory = widgetStrategyFactory;
  this.cache = Maps.newConcurrentMap();
  this.counter = metricRegistry.counter(name(getClass(), "cacheEntries"));
}

代码示例来源:origin: confluentinc/ksql

CommandStore(
  final CommandTopic commandTopic,
  final CommandIdAssigner commandIdAssigner,
  final SequenceNumberFutureStore sequenceNumberFutureStore
) {
 this.commandTopic = Objects.requireNonNull(commandTopic, "commandTopic");
 this.commandIdAssigner = Objects.requireNonNull(commandIdAssigner, "commandIdAssigner");
 this.commandStatusMap = Maps.newConcurrentMap();
 this.sequenceNumberFutureStore =
   Objects.requireNonNull(sequenceNumberFutureStore, "sequenceNumberFutureStore");
}

代码示例来源:origin: guoguibing/librec

@Override
protected void setup() throws LibrecException {
  super.setup();
  itemPops = Maps.newConcurrentMap();
}

代码示例来源:origin: apache/kylin

public void addContext(int ctxId, String type, boolean ifCube) {
  ConcurrentMap<String, ConcurrentMap<String, CubeSegmentStatistics>> cubeSegmentStatisticsMap = null;
  if (ifCube) {
    cubeSegmentStatisticsMap = Maps.newConcurrentMap();
  }
  cubeSegmentStatisticsResultMap.put(ctxId, new CubeSegmentStatisticsResult(type, cubeSegmentStatisticsMap));
}

代码示例来源:origin: google/guava

final Iterable<Method> getInstanceMethods(Class<?> cls) {
 ConcurrentMap<Signature, Method> map = Maps.newConcurrentMap();
 for (Method method : getVisibleMethods(cls)) {
  if (!Invokable.from(method).isStatic()) {
   map.putIfAbsent(new Signature(method), method);
  }
 }
 return map.values();
}

代码示例来源:origin: google/guava

public void testConcurrentMap() {
 ConcurrentMap<Integer, Integer> map = Maps.newConcurrentMap();
 assertEquals(Collections.emptyMap(), map);
}

代码示例来源:origin: ctripcorp/apollo

/**
 * Constructor.
 */
public RemoteConfigLongPollService() {
 m_longPollFailSchedulePolicyInSecond = new ExponentialSchedulePolicy(1, 120); //in second
 m_longPollingStopped = new AtomicBoolean(false);
 m_longPollingService = Executors.newSingleThreadExecutor(
   ApolloThreadFactory.create("RemoteConfigLongPollService", true));
 m_longPollStarted = new AtomicBoolean(false);
 m_longPollNamespaces =
   Multimaps.synchronizedSetMultimap(HashMultimap.<String, RemoteConfigRepository>create());
 m_notifications = Maps.newConcurrentMap();
 m_remoteNotificationMessages = Maps.newConcurrentMap();
 m_responseType = new TypeToken<List<ApolloConfigNotification>>() {
 }.getType();
 gson = new Gson();
 m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
 m_httpUtil = ApolloInjector.getInstance(HttpUtil.class);
 m_serviceLocator = ApolloInjector.getInstance(ConfigServiceLocator.class);
 m_longPollRateLimiter = RateLimiter.create(m_configUtil.getLongPollQPS());
}

代码示例来源:origin: google/guava

public void testConcurrentMap() {
 assertFreshInstance(new TypeToken<ConcurrentMap<String, ?>>() {});
 assertCanGenerateOnly(
   new TypeToken<ConcurrentMap<EmptyEnum, String>>() {}, Maps.newConcurrentMap());
}

代码示例来源:origin: apache/ignite

/**
 * @param ignMsg IgniteMessaging.
 * @throws Exception If failed.
 */
private void sendOrderedMultiThreads(
    final IgniteMessaging ignMsg
) throws Exception {
  final ConcurrentMap<String, List<String>> expMsg = Maps.newConcurrentMap();
  final ConcurrentMap<String, List<String>> actlMsg = Maps.newConcurrentMap();
  final List<String> msgs = orderedMessages();
  sendOrderedMultiThreads(ignMsg, expMsg, actlMsg, msgs);
}

代码示例来源:origin: apache/kylin

@Test
  public void testExecute() throws ExecuteException {
    UpdateSnapshotCacheForQueryServersStep step = new UpdateSnapshotCacheForQueryServersStep();
    ExecuteResult result = step.doWork(new DefaultContext(Maps.<String, Executable>newConcurrentMap(), kylinConfig));
    System.out.println(result.output());
    assertTrue(result.succeed());
  }
}

相关文章