Pay for Hesitation: thread

Pages

顯示具有 thread 標籤的文章。 顯示所有文章
顯示具有 thread 標籤的文章。 顯示所有文章

2010年11月17日 星期三

CopyOnWriteArrayList

http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/CopyOnWriteArrayList.html
A thread-safe variant of ArrayList in which all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array.
This is ordinarily too costly, but may be more efficient than alternatives when traversal operations vastly outnumber mutations, and is useful when you cannot or don't want to synchronize traversals, yet need to preclude interference among concurrent threads. The "snapshot" style iterator method uses a reference to the state of the array at the point that the iterator was created. This array never changes during the lifetime of the iterator, so interference is impossible and the iterator is guaranteed not to throwConcurrentModificationException. The iterator will not reflect additions, removals, or changes to the list since the iterator was created. Element-changing operations on iterators themselves (remove, set, and add) are not supported. These methods throw UnsupportedOperationException.


原來JAVA 1.5 API有這種東西,
當初寫IMCrowd我為了解決list iteration 和 list modification丟出concurrentModificationException的問題,
先後還嘗試實作semaphore及額外維護一個list copy. 冏rz

2010年3月17日 星期三

Threads in ActionScript 3

ActionScript 3 is a single-thread execution model; therefore, it doesn’t support multi-thread programming technique.

However, there are some tricks for asynchronous computation below.
Threads in ActionScript 3
Asynchronous ActionScript Execution
CJ's Blog: Asynchronous Computation
Mutexes in ActionScript and JavaScript

There is also a third-party thread library for Actionscript 3.
http://www.libspark.org/htdocs/as3/thread/