I know the threading topic has been discussed quite extensively, but I still
need some guidance in the following case:
My application has a RuleManager object that maintains references to many
RuleBase objects in a HashMap. I'm using Spring Framework to wire the bean
relationships together.
The RulesManager is typically busy servicing client requests for instances
of WorkingMemory objects which it fetches from the individual RuleBase
objects it maintains in its Hash (wm.newWorkingMemory() ).
From time to time, I'll need RulesManager to reaload the rules
that are
associated with the individual RuleBase object - for that, I'm going
to
create a new instance of the RuleBase object and then I need an efficient
and safe way to 'swap' this new RuleBase object for the old object reference
in the RulesManager's map.
My question is: should I synchronize the getWorkingMemory(..) method inside
my RulesManager object that uses the hashmap, AND also synchronize the code
that does the object swap - would that be sufficient?! How would I do it
using Collections.synchronizedMap() - remember that I don't have that much
control over the creation of the Map since Spring controls that part of
populating hashmap at startup.
The critical factors for me are speed and efficiency in servicing regular
client requests for WorkingMemory - ideally, I'd synchronize only the method
that does the object swap, but I'm sure that may have some bad
consequences... though as long as I can avoid the race condition I could
probably live with it.
Thanks in advance for ideas -
--
View this message in context:
http://www.nabble.com/Question-on-data-safety-and-threading...-tf3396050....
Sent from the drools - user mailing list archive at
Nabble.com.