I think I have an answer after further thought:
NOTE. My answer depends on the fact that both factories are idempotent with respect to its string key, and workers are all idempotent with respect to their factory, which may not have been obvious from the question.
For the first global hash of a file based on a singleton key, I use the idea that hashmap never has deletions. Only new idempotent ones. Therefore, I use the volatile hashmap reference, and get the current map from the volatile singleton variable without a mutex. (the volatility of getting links is currently very contradictory in Java). If the card is outdated, in the sense that it does not have all the current factories, this is normal. Because if he has a factory (usually he will warm up), I have it. With only the cost of volatile receipt. If he doesn’t have one, I’ll now consult a live map to get inside the mutex for a live map. If I get the factory from the card now (unlikely), I succeeded. Otherwise, now I am doing a very expensive operation of creating a factory (outside of the mutexes). When you are done, I will return to the live map with the mutex, and because another thread is doing the same thing, it might be there now! Therefore, if a factory is present on the map, I throw away the wasted factory that I just created and use the one that was put there in front of me. Otherwise, I overlay the new factory on the map, leave the mutex and start using the factory.
I do not think it is better for this.
In softcache factory, I think I just want to use ConcurrentLinkedQueue. However, my items will be links to softreferences. Therefore, I deduce from ConcurrentLinkedQueue an object that refers to a soft link to the employee himself. The worker may have been relaxed, so I re-create the worker from the factory and re-create the soft link in the object that I got from ConcurrentLinkedQueue, and set the soft link to the employee. Thus, there is no mutex to get the worker from the factory, just checking ConcurrentLinkedQueue, and the links to the worker are soft.
source share