是java.util.Observable中在Android的线程安全的?线程、安全、util、java

2023-09-04 23:33:40 作者:相关八字微信推荐>>

时java.util.Observable中在Android的线程安全的?该文档说,只有deleteObserver()和deleteObservers()是同步的方法。怎么样的addObserver(),设置/清除/ hasChanged()?我可以安全地调用的addObserver()从不同的线程周围没有可观察的对象锁定?

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 addObserver() from different threads without locking around the Observable object?

推荐答案

AFAIK,Android的基于Apache和谐。我发现了观测实施和谐这里的来源$ C ​​$ C:http://www.java2s.com/Open-Source/Java-Document/Apache-Harmony-Java-SE/java-package/java/util/Observable.java.htm.

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.

在我看来,这将试图使它线程安全的,但没有成功。他们忘了同步countObservers方法,以及设定/有/ clearChanged方法

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.