Originally posted by Mingwei Jiang:
Although the instructions told me nothing regarding performance and synchronization, which means I can either choose to synchronize them or not to synchronize them, I'd like to know what's the better way to implement the Data class without synchronization.
In my mind, if I don't wanna do the synchronization and want a better performance. I will choose to have multiple RandomAccessFile instances managed in the Data instance with each serves a client request. Like when one RandomAccessFile instance is updating the record, another RandomAccessFile can also do the creation, deletion and updation of the record as long as they are not accessing the same record.
Is there anyone who has the same thoughts or better ones? For the exam alone, I will choose the synchronization solution, since the instructions didn't say anything about that and it's easier to implement. But as a learner, I'd like to know the sophisticated one, the one without synchronization.
I used multiple data instances for each public client request. My reasoning for this was that it would improve performance by allowing for greater throughput and that it would make the code easier to understand for a junior programmer.
However after submission I did some tests and found that my data version with the local RandomAccessFile instances ran about five times slower that a Version with a single synchronized RAF file. While multiple RAF instances sounds good in theory in reality the overhead involved in opening a new RAF for each client request is actually very high compared to the performance bottleneck of each
thread sharing a single RAF instance.
I went with the local RAF instances in the end but plenty of people have passed using both approaches. Once you have stated a good enough reaon for using one approach over the other you will be fine