java.util.Collections.synchronizedCollection()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(157)

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

Collections.synchronizedCollection介绍

[英]Returns a wrapper on the specified collection which synchronizes all access to the collection.
[中]返回指定集合上的包装器,该包装器同步对集合的所有访问。

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy

/**
 * A convenience method for creating a synchronized Collection.
 *
 * @param self a Collection
 * @return a synchronized Collection
 * @see java.util.Collections#synchronizedCollection(java.util.Collection)
 * @since 1.0
 */
public static <T> Collection<T> asSynchronized(Collection<T> self) {
  return Collections.synchronizedCollection(self);
}

代码示例来源:origin: org.netbeans.api/org-openide-util-lookup

/** Marks this item as being deserialized.
 */
public void markDeserialized() {
  if (items == null || items == Collections.EMPTY_LIST) {
    items = Collections.emptyList();
  } else {
    items = Collections.synchronizedCollection(items);
  }
}

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

private Dataset(Builder builder) {
 this.inputPaths = builder.inputPaths;
 this.inputLatePaths = builder.inputLatePaths;
 this.outputPath = builder.outputPath;
 this.outputLatePath = builder.outputLatePath;
 this.outputTmpPath = builder.outputTmpPath;
 this.additionalInputPaths = Sets.newHashSet();
 this.throwables = Collections.synchronizedCollection(Lists.<Throwable> newArrayList());
 this.priority = builder.priority;
 this.lateDataThresholdForRecompact = builder.lateDataThresholdForRecompact;
 this.state = new AtomicReference<>(DatasetState.UNVERIFIED);
 this.datasetName = builder.datasetName;
 this.jobProps = builder.jobProps;
 this.renamePaths = builder.renamePaths;
}

代码示例来源:origin: wildfly/wildfly

public Collection<V> values() {
  synchronized(mutex) {
    if(values == null)
      values=Collections.synchronizedCollection(map.values());
    return values;
  }
}

代码示例来源:origin: wildfly/wildfly

classes.add(Collections.checkedSortedSet(Collections.emptySortedSet(), Void.class).getClass());
classes.add(Collections.synchronizedCollection(randomAccessList).getClass());
classes.add(Collections.synchronizedCollection(nonRandomAccessList).getClass());
classes.add(Collections.synchronizedList(randomAccessList).getClass());
classes.add(Collections.synchronizedList(nonRandomAccessList).getClass());

代码示例来源:origin: protostuff/protostuff

.synchronizedCollection(Collections.emptyList()); // no

代码示例来源:origin: banq/jdonframework

public Collection<String> getComponentNames() {
  return Collections.synchronizedCollection(dirs.values());
}

代码示例来源:origin: didi/DDMQ

public static Collection<Object> getFilterdMessage(Collection<Object> sendMsgs,
  Collection<Object> recvMsgs) {
  Collection<Object> recvMsgsSync = Collections.synchronizedCollection(recvMsgs);
  Collection<Object> filterdMsgs = new ArrayList<Object>();
  int filterNum = 0;
  for (Object msg : recvMsgsSync) {
    if (sendMsgs.contains(msg)) {
      filterdMsgs.add(msg);
    } else {
      filterNum++;
    }
  }
  logger.info(String.format("[%s] messages is filterd!", filterNum));
  return filterdMsgs;
}

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

futures.add(pool.submit(() -> {
 KafkaProducer<String, String> producer = kafkaProducer.get();
 Collection<Future<?>> b = Collections.synchronizedCollection(new ArrayList<>());
 for (int i = 0; i < batchSize; ++i) {
  b.add(sendToKafka(producer, kafkaTopic, messageSupplier.get()));

代码示例来源:origin: didi/DDMQ

for (AbstractListener listener : listeners) {
  Collection<Object> recvMsgs = Collections
    .synchronizedCollection(listener.getAllUndupMsgBody());
  noDupMsgs.addAll(VerifyUtils.getFilterdMessage(allSendMsgs, recvMsgs));

代码示例来源:origin: de.javakaffee/kryo-serializers

@Override
  public Object create( final Object sourceCollection ) {
    return Collections.synchronizedCollection( (Collection<?>) sourceCollection );
  }
},

代码示例来源:origin: org.kohsuke.droovy/groovy

/**
 * A convenience method for creating a synchronized Collection.
 *
 * @param self a Collection
 * @return a synchronized Collection
 * @see java.util.Collections#synchronizedCollection(java.util.Collection)
 * @since 1.0
 */
public static Collection asSynchronized(Collection self) {
  return Collections.synchronizedCollection(self);
}

代码示例来源:origin: in.jlibs/org-openide-util

/** Marks this item as being deserialized.
 */
public void markDeserialized() {
  if (items == null || items == Collections.EMPTY_LIST) {
    items = Collections.emptyList();
  } else {
    items = Collections.synchronizedCollection(items);
  }
}

代码示例来源:origin: stackoverflow.com

Collection c = Collections.synchronizedCollection(myCollection);
  ...
synchronized(c) {
  Iterator i = c.iterator(); // Must be in the synchronized block
  while (i.hasNext())
    foo(i.next());
}

代码示例来源:origin: apache/activemq-artemis

public Collection<V> values() {
  synchronized(mutex) {
    if(values == null)
      values=Collections.synchronizedCollection(map.values());
    return values;
  }
}

代码示例来源:origin: apache/activemq-artemis

public Collection<V> values() {
  synchronized(mutex) {
    if(values == null)
      values=Collections.synchronizedCollection(map.values());
    return values;
  }
}

代码示例来源:origin: org.apache.activemq/artemis-jms-client-all

public Collection<V> values() {
  synchronized(mutex) {
    if(values == null)
      values=Collections.synchronizedCollection(map.values());
    return values;
  }
}

代码示例来源:origin: com.mchange/mchange-commons-java

public static Collection narrowSynchronizedCollection( Collection c )
{
if (c instanceof SortedSet)
  return Collections.synchronizedSortedSet( (SortedSet) c );
else if (c instanceof Set)
  return Collections.synchronizedSet( (Set) c );
else if (c instanceof List)
  return Collections.synchronizedList( (List) c );
else
  return Collections.synchronizedCollection( c );
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

public Collection<V> values() {
  synchronized(mutex) {
    if(values == null)
      values=Collections.synchronizedCollection(map.values());
    return values;
  }
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.vfs

/**
 * 
 */
void clear()
{
  this.buffer = new byte[0];
  updateLastModified();
  this.type = FileType.IMAGINARY;
  this.children = Collections.synchronizedCollection(new ArrayList());
  this.name = null;
}

相关文章

微信公众号

最新文章

更多

Collections类方法