开发者

Is java.util.Observable in Android thread-safe?

开发者 https://www.devze.com 2023-02-14 01:16 出处:网络
Is java.util.Observable in Android thread-safe? The documentation says that only deleteObserver() and deleteObservers() are synchronized methods. What about addObserver(), set/clear/hasChanged()? Can

Is java.util.Observable in Android thread-safe? The documentation says that only deleteObserver() and deleteObservers() are synchronized methods. What about addObserver(), set/clear/hasChanged()? Can I safely call 开发者_StackOverflow中文版addObserver() from different threads without locking around the Observable object?


AFAIK, Android is based on Apache Harmony. I found the source code of the the Observable implementation of Harmony here : http://www.java2s.com/Open-Source/Java-Document/Apache-Harmony-Java-SE/java-package/java/util/Observable.java.htm.

It seems to me that the tried to make it thread-safe, but failed : they forgot to synchronize the countObservers method, as well as the set/has/clearChanged methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消