Le 01/07/15 10:31, Zheng, Kai a écrit : >>> you should protect the cache no matter what, even the query part. What >>> would happen if you are reading the cache while another thread is reading >>> it ? > It's the same meaning with what I meant when said, "the LinkedHashMap should > be protected since there may be many querying that need to update the cache". > > In addition to that, I mentioned the two cases of using the backend APIs to > explain why those interface methods are not synchronized. I would add some > comments about this later.
Probbaly some misunderstanding on my side... What I wanted to say is that any method which manipulate the cache (either for read or wraite) must be thread safe. I guess this is what you have in mind to. Also note that Synchronize is not necessarilly the best tool for that. Locks could be good enough, and we can even thing about using a ThreadLocalStorage to store the cache, so that we don't need any synchronization at all (but the price is that you will eat more memory). Thanks Kai !
