hello,everybody! can someone comments on my design? my version is 1.1.3,I study others' design,decide to cache all data in memory,put them in a arraylist(i am not sure it is right),recno start from 0,the record deleted also in it and have recno. the most confuse me that the locking,I don't need record level,but I want It can multi read at the same time,so I want synchronize the arraylist when lock unlock update.Can someone give me some advice.
Don't worry about locking at the record level for each record, lock the whole list. The other threads can wait to read while you update a record. Locking at the record level is not necessary, so somehing like this, in the DB class, or the implementor:
I locked each record at the record level, and had a queue on the lists, and I lost marks, so keep it simple. Lock the whole list, modify, then unlock, simple. You don't have to have bullet proof code like DB2, and efficiency you don't have to worry about.
Hope this helps.
Joined: Jul 28, 2004
my interface has not the declare: public synchronized int lock(int recno) ;instead of public int lock(int recno) ; and I cache all the data in a arraylist,so I synchronized the arraylist do you think it is proper
Joined: Nov 15, 2003
Sorry about the long delay, don't look at these forums every day.
If I understand you correctly, your interface is:
And you don't want to break the method signature. But you can change some modifiers. That is no problem, you can change the implementation of that method and include a "synchronized" modifier, no problem. But you said that you are synchronising on the list, that is also ok. Most of the people synchronised on the Data class, I think because it is easier. But synchronising on the list should be fine.