List of usage examples for java.util Collections synchronizedCollection
public static <T> Collection<T> synchronizedCollection(Collection<T> c)
From source file:Main.java
public static void main(String[] args) { Collection<String> c = Collections.synchronizedCollection(new ArrayList<String>()); List<String> list = Collections.synchronizedList(new ArrayList<String>()); Set<String> s = Collections.synchronizedSet(new HashSet<String>()); Map<String, String> m = Collections.synchronizedMap(new HashMap<String, String>()); }
From source file:Synchronization.java
public static void main(String[] args) { Collection c = Collections.synchronizedCollection(new ArrayList()); List list = Collections.synchronizedList(new ArrayList()); Set s = Collections.synchronizedSet(new HashSet()); Map m = Collections.synchronizedMap(new HashMap()); }
From source file:Main.java
public static void main(String[] args) { // create vector object List<String> vector = new ArrayList<String>(); // populate the vector vector.add("1"); vector.add("2"); vector.add("3"); vector.add("4"); vector.add("from java2s.com"); // create a synchronized view Collection<String> c = Collections.synchronizedCollection(vector); System.out.println("Sunchronized view is :" + c); }
From source file:Main.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/*from w w w. jav a 2s . co m*/ return Collections.synchronizedCollection(c); }
From source file:org.jactr.tools.tracer.sinks.NetworkedSink.java
public NetworkedSink() { RemoteInterface ri = RemoteInterface.getActiveRemoteInterface(); if (ri == null) throw new RuntimeException("A RemoteInterface must be active before instantiating this sink"); _handler = ri.getHandler();/*w w w .j av a2 s. c om*/ try { MAXIMUM_BUFFER_SIZE = Integer.parseInt(System.getProperty("jACTR:MaximumBufferSize")); } catch (NumberFormatException nfe) { MAXIMUM_BUFFER_SIZE = 25; } _messageBuffer = Collections.synchronizedCollection(new FastList<IMessage>()); _autoFlush = new Runnable() { public void run() { // no need for this to be safe.. _scheduled = false; try { flush(); } catch (Exception e) { LOGGER.error(".run threw Exception : ", e); } } }; }
From source file:org.efaps.webdav4vfs.test.ramvfs.RamFileData.java
/** * *//* w w w . j a v a 2s . c o m*/ void clear() { this.buffer = new byte[0]; updateLastModified(); this.type = FileType.IMAGINARY; this.children = Collections.synchronizedCollection(new ArrayList<RamFileData>()); this.name = null; }
From source file:ch.chrigu.datastructures.demo.instances.CollectionInstance.java
/** * The best matching {@link Collections}'s synchronized... function is applied. *//* w ww . java 2 s. c om*/ private Collection<T> synchronizedCollection(Collection<T> instance) { if (instance instanceof List) { return Collections.synchronizedList((List<T>) instance); } if (instance instanceof Set) { if (instance instanceof NavigableSet) { return Collections.synchronizedNavigableSet((NavigableSet<T>) instance); } return Collections.synchronizedSet((Set<T>) instance); } return Collections.synchronizedCollection(instance); }
From source file:gobblin.compaction.dataset.Dataset.java
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; }
From source file:ubic.gemma.ontology.providers.MgedOntologyService.java
/** * @return Returns the Mged Ontology Terms that are usefull for annotating Gemma. Basically the terms in the * bioMaterial package plus some special cases. *///from w w w. j a v a 2 s . co m public Collection<OntologyTerm> getUsefulMgedTerms() { if (!isInitialized.get()) { log.warn("MGED Ontology is not loaded (yet?)"); return new HashSet<OntologyTerm>(); } Collection<OntologyTerm> results = getBioMaterialTerms(); results = Collections.synchronizedCollection(results); // A bunch of terms not in the biomaterial package that we need. (special cases) OntologyTerm term = terms.get(ontology_URL + "#ExperimentPackage"); results.addAll(getAllTerms(term)); term = terms.get(ontology_URL + "#MeasurementPackage"); results.addAll(getAllTerms(term)); term = terms.get(ontology_URL + "#MGEDExtendedOntology"); results.addAll(getAllTerms(term)); // trim some terms out: Collection<OntologyTerm> trimmed = Collections.synchronizedSet(new HashSet<OntologyTerm>()); for (OntologyTerm mgedTerm : results) { if (!TermsToRemove.contains(mgedTerm.getTerm())) { trimmed.add(mgedTerm); } } return trimmed; }
From source file:org.apps8os.logger.android.fragment.LoggerPanelFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); initCustomView();/*w w w . ja v a 2s . c om*/ if (mEventCount != null) { mEventCount.setText("0"); mEventCount.setVisibility(View.VISIBLE); } if (mActionEventList == null) { mActionEventList = new ArrayList<ActionEvent>(); Collections.synchronizedCollection(mActionEventList); } }