5

I know neither HashMap nor SparseArray are threadsafe. Do I have to worry about that if I have a central data repository as HashMap which can be accessed by the activity and potentially by an AsyncTask?

Would it be advisable to use a HashTable or better ConcurrentHashMap to be on the safe side?

4

1 回答 1

4

是的,您将不得不担心线程安全。每当您围绕 HashMap 或 SparseArray 执行 IO 时,您都可以使用 HashTable、ConcurrentHashMap 或同步块。同步块的行为有点不同,可能会更慢,但对于简单的应用程序,这可能不是问题。

于 2015-02-17T21:35:23.397 回答