Collections.SynchronizedSortedSet(ISortedSet) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳一個同步(執行緒安全)的排序集合,並由指定的排序集合作為後盾。
[Android.Runtime.Register("synchronizedSortedSet", "(Ljava/util/SortedSet;)Ljava/util/SortedSet;", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static Java.Util.ISortedSet SynchronizedSortedSet(Java.Util.ISortedSet s);
[<Android.Runtime.Register("synchronizedSortedSet", "(Ljava/util/SortedSet;)Ljava/util/SortedSet;", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member SynchronizedSortedSet : Java.Util.ISortedSet -> Java.Util.ISortedSet
參數
排序集合會被「包裹」成同步排序集合。
傳回
一個對指定排序集合的同步視圖。
- 屬性
備註
回傳一個同步(執行緒安全)的排序集合,並由指定的排序集合作為後盾。 為了保證序列存取,必須 <透過回傳的排序集合(或其視圖)來實現對後備排序集合的強>全/<強> 存取。
使用者在遍歷該排序集或其任何 、 、 或視圖時,必須手動同步該排序集,透過 或 SpliteratorStream:IteratortailSetheadSetsubSet
SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
...
synchronized (s) {
Iterator i = s.iterator(); // Must be in the synchronized block
while (i.hasNext())
foo(i.next());
}
或:
SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
SortedSet s2 = s.headSet(foo);
...
synchronized (s) { // Note: s, not s2!!!
Iterator i = s2.iterator(); // Must be in the synchronized block
while (i.hasNext())
foo(i.next());
}
若不遵循此建議,可能導致非決定性行為。
若指定的排序集合可序列化,則回傳的排序集合將具備序列化能力。
的 java.util.Collections.synchronizedSortedSet(java.util.SortedSet<T>)Java 檔。
此頁面的部分是根據 Android 開放原始碼專案所建立和共用的工作進行修改,並根據 Creative Commons 2.5 屬性授權中所述的詞彙使用。