是java.util.Observable中在Android的线程安全的? [英] Is java.util.Observable in Android thread-safe?

查看:171
本文介绍了是java.util.Observable中在Android的线程安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时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:<一href="http://www.java2s.com/Open-Source/Java-Document/Apache-Harmony-Java-SE/java-package/java/util/Observable.java.htm" rel="nofollow">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.

这篇关于是java.util.Observable中在Android的线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆