multiple (non-nested) synchronized blocks in single method
Joined: Feb 23, 2004
I just decided to switch my implementation of Data.java to implement caching. I am caching the entire database, and writing to file from the methods that modify data (delete, update, create). My question is on using multiple synchronized blocks in a single method, and whether this is bad style or not. Consider the following:
I have 2 synchronized maps, one for keeping track of locked records, and one for storing actual records. Let's call them lockedRecords and recordCache. Also, each client shares one single instance of Data. Now consider my implementation of update:
Is this implementation acceptable?
B.S. University of Wisconsin<br />SCJP 1.4 (85%)<br />SCJD 1.4 (92%) B&S Contractors
Joined: Aug 10, 2004
two quesitons. Assuming we are looking at Data. Is it neccary to check the lock on the update? Not in the requirments but most important of all cant do this if your implementing DBMain right because the DBMain update doesnt throw a security excpetion? (ofcourse your assignment requirements might be diffrent from mine).
Secondly when you update and read the cache if you use synchronized container type then it wont be neccary to synchronize. Thats how I am doing it anyways.