Collections.SynchronizedNavigableSet(INavigableSet) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a synchronized (thread-safe) navigable set backed by the specified navigable set.
[Android.Runtime.Register("synchronizedNavigableSet", "(Ljava/util/NavigableSet;)Ljava/util/NavigableSet;", "", ApiSince=26)]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static Java.Util.INavigableSet SynchronizedNavigableSet (Java.Util.INavigableSet s);
[<Android.Runtime.Register("synchronizedNavigableSet", "(Ljava/util/NavigableSet;)Ljava/util/NavigableSet;", "", ApiSince=26)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member SynchronizedNavigableSet : Java.Util.INavigableSet -> Java.Util.INavigableSet
Parameters
the navigable set to be "wrapped" in a synchronized navigable set
Returns
a synchronized view of the specified navigable set
- Attributes
Remarks
Returns a synchronized (thread-safe) navigable set backed by the specified navigable set. In order to guarantee serial access, it is critical that <strong>all</strong> access to the backing navigable set is accomplished through the returned navigable set (or its views).
It is imperative that the user manually synchronize on the returned navigable set when traversing it, or any of its subSet
, headSet
, or tailSet
views, via Iterator
, Spliterator
or Stream
:
NavigableSet s = Collections.synchronizedNavigableSet(new TreeSet());
...
synchronized (s) {
Iterator i = s.iterator(); // Must be in the synchronized block
while (i.hasNext())
foo(i.next());
}
or:
NavigableSet s = Collections.synchronizedNavigableSet(new TreeSet());
NavigableSet s2 = s.headSet(foo, true);
...
synchronized (s) { // Note: s, not s2!!!
Iterator i = s2.iterator(); // Must be in the synchronized block
while (i.hasNext())
foo(i.next());
}
Failure to follow this advice may result in non-deterministic behavior.
The returned navigable set will be serializable if the specified navigable set is serializable.
Added in 1.8.
Java documentation for java.util.Collections.synchronizedNavigableSet(java.util.NavigableSet<T>)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.