Reputation: 16865
I'm storing objects in a ThreadLocal
Map
( implemented in spring-tx)
class TransactionSynchronizationManager ...
private static final ThreadLocal<Map<Object, Object>> resources =
new NamedThreadLocal<Map<Object, Object>>("Transactional resources");
if the Map is ThreadLocal
and properly accessed (again all spring-tx code), do the values I store in the map have to be ThreadLocal to be thread safe?
Upvotes: 0
Views: 122
Reputation: 53694
Assuming you haven't inadvertently passed the Map to another thread by some other means, the Map does not need any additional protection, because all usage of it will be single-threaded. Likewise, as long as any Objects in the Map are not inadvertently passed to other threads by other means, those Objects do not need any additional protection.
Upvotes: 2