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

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

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

Collections.synchronizedList介绍

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

代码示例

代码示例来源:origin: junit-team/junit4

public SerializedForm(Result result) {
  fCount = result.count;
  fIgnoreCount = result.ignoreCount;
  assumptionFailureCount = result.assumptionFailureCount;
  fFailures = Collections.synchronizedList(new ArrayList<Failure>(result.failures));
  fRunTime = result.runTime.longValue();
  fStartTime = result.startTime.longValue();
}

代码示例来源:origin: weibocom/motan

@Override
public void registerListener(String switcherName, SwitcherListener listener) {
  List listeners = Collections.synchronizedList(new ArrayList());
  List preListeners= listenerMap.putIfAbsent(switcherName, listeners);
  if (preListeners == null) {
    listeners.add(listener);
  } else {
    preListeners.add(listener);
  }
}

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

public <T> void registerImplementer(Class<T> configInterface, Class<? extends T> ...implementation) {
  List<Class> set;
  if (registry.containsKey(configInterface)) {
    set = registry.get(configInterface);
  } else {//TODO: concurrency issue -jj (someone sets set before putIfAbsent)
    List<Class> newSet = Collections.synchronizedList(new ArrayList<>());
    set = registry.putIfAbsent(configInterface, newSet);
    if (set == null) {
      set = newSet;
    }
  }
  set.addAll(Arrays.asList(implementation));
}

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

/**
 * Constructs a basic coalescence animation.
 *
 * @param rootConfig {@link CoalesceConfig} The root object of the animation. This is simply the first item in
 *                                         item in the animation list.
 */
public CoalesceAnimation3D(CoalesceConfig rootConfig) {
  mCoalesceObjects = Collections.synchronizedList(new CopyOnWriteArrayList<CoalesceConfig>());
  mThetaRanges = Collections.synchronizedList(new CopyOnWriteArrayList<Double>());
  mTransformable3D = rootConfig.object;
  mCoalesceObjects.add(rootConfig);
  mThetaRanges.add(rootConfig.spiral.calculateThetaForRadius(rootConfig.endProximity));
}

代码示例来源:origin: Bilibili/DanmakuFlameMaster

public void registerConfigChangedCallback(ConfigChangedCallback listener) {
  if (listener == null || mCallbackList == null) {
    mCallbackList = Collections.synchronizedList(new ArrayList<WeakReference<ConfigChangedCallback>>());
  }
  for (WeakReference<ConfigChangedCallback> configReferer : mCallbackList) {
    if (listener.equals(configReferer.get())) {
      return;
    }
  }
  mCallbackList.add(new WeakReference<ConfigChangedCallback>(listener));
}

代码示例来源:origin: weibocom/motan

/**
 * Get the notes list for the given location. If missing, create it.
 */
private List<RouteNote> getOrCreateNotes(Point location) {
 List<RouteNote> notes = Collections.synchronizedList(new ArrayList<RouteNote>());
 List<RouteNote> prevNotes = routeNotes.putIfAbsent(location, notes);
 return prevNotes != null ? prevNotes : notes;
}

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

private List<Class<?>> findSubclasses(Map<URL, String> locations, String searchingPackageName) {
  List<Class<?>> v = synchronizedList(new ArrayList<Class<?>>());
  List<Class<?>> w = null;
  for (URL url : locations.keySet()) {
    // search just required packages
    String packageName = locations.get(url);
    if (packageName.startsWith(searchingPackageName)) {
      w = findSubclasses(url, packageName, searchingPackageName);
      if (w != null && w.size() > 0) {
        v.addAll(w);
      }
    }
  }
  return v;
}

代码示例来源:origin: jamesdbloom/mockserver

@Override
public synchronized V put(K key, V value) {
  if (containsKey(key)) {
    backingMap.get(key).add(value);
  } else {
    List<V> list = Collections.synchronizedList(new CircularLinkedList<V>(maxValuesPerKeySize));
    list.add(value);
    backingMap.put(key, list);
  }
  return value;
}

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

public void record(String key, String value) {
  List<String> values = entries.get(key);
  if (values == null) {
    entries.putIfAbsent(key, Collections.synchronizedList(new ArrayList<String>()));
    // At this point, there will definitely be a list for the key.
    // We don't know or care which thread's new object is in there, so:
    values = entries.get(key);
  }
  values.add(value);
}

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

public AsyncContext(List<T> inputs, Semaphore throttle, SettableFuture<List<T>> settableFuture) {
  this.inputs = inputs;
  this.latch = new AtomicInteger(inputs.size());
  this.throttle = throttle;
  this.exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
  this.future = settableFuture;
}

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

List list = Collections.synchronizedList(new ArrayList());
 // Thread 1
 List list2 = ...
 for (Object element : list2) {
   list.add(element);
 }
 // Thread 2
 List list3 = ...
 for (Object element : list) {
   list3.add(element);
 }

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * @param inputAcceptor
 * @param outputProducer
 */
public StepIOMeta( boolean inputAcceptor, boolean outputProducer, boolean inputOptional,
 boolean sortedDataRequired, boolean inputDynamic, boolean outputDynamic ) {
 this.inputAcceptor = inputAcceptor;
 this.outputProducer = outputProducer;
 this.inputOptional = inputOptional;
 this.sortedDataRequired = sortedDataRequired;
 this.streams = java.util.Collections.synchronizedList( new ArrayList<StreamInterface>() );
 this.inputDynamic = inputDynamic;
 this.outputDynamic = outputDynamic;
}

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

List<String> list = Collections.synchronizedList(new ArrayList<String>());
list.add("hello");

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

Collections.synchronizedList(new ArrayList<YourClassNameHere>())

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

public static List listDataFormats() {
  List list = new ArrayList();
  Format[] formats = GridFormatFinder.getFormatArray();
  final int length = formats.length;
  for (int i = 0; i < length; i++) {
    if (!list.contains(formats[i])) {
      list.add(formats[i]);
    }
  }
  return Collections.synchronizedList(list);
}

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

public AggregatedBdbEnvironmentStats() {
  environmentStatsTracked = Collections.synchronizedList(new ArrayList<BdbEnvironmentStats>());
}

代码示例来源:origin: networknt/light-4j

@Override
public void registerListener(String switcherName, SwitcherListener listener) {
  synchronized (listenerMap) {
    if (listenerMap.get(switcherName) == null) {
      List listeners = Collections.synchronizedList(new ArrayList());
      listenerMap.put(switcherName, listeners);
      listeners.add(listener);
    } else {
      List listeners = listenerMap.get(switcherName);
      if (!listeners.contains(listener)) {
        listeners.add(listener);
      }
    }
  }
}

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

List<Object> objList = Collections.synchronizedList(new ArrayList<Object>());

代码示例来源:origin: jamesdbloom/mockserver

@Override
public synchronized NottableString put(NottableString key, NottableString value) {
  List<NottableString> list = Collections.synchronizedList(new ArrayList<NottableString>());
  for (Entry<NottableString, NottableString> entry : entryList()) {
    if (EqualsBuilder.reflectionEquals(entry.getKey(), key)) {
      list.add(entry.getValue());
    }
  }
  list.add(value);
  backingMap.put(key, list);
  return value;
}

代码示例来源:origin: reactor/reactor-core

ColdTestPublisher() {
  this.values = Collections.synchronizedList(new ArrayList<>());
}

相关文章

Collections类方法