Hi Fei, synchronizing the entire method, while technically could work, you need to take into consideration performance. Imagine a scenario where many threads are vying for access to the methods of your object. Each of them having to wait for the entire method to execute before they could possibly have their turn, would invariably result in poor performance. The best approach with multi-threaded programming is to synchronize only the resources that's state can be affected by multiple threads. This could be the RandomAccessFile object in your data class, or some sort of map object in a locking class. This approach does require you to think carefully about your design, but the improvements in performance are well worth it. Hope this helps.
SCJP 1.4 SCJD 1.5
posted 12 years ago
thank Mike Ottinger to your reply, another reason that the DB interface is general interface and does not provide contract that any clients must synchronized prior to use.
Best regards. Mohamed Darim.
What are your superhero powers? Go ahead and try them on this tiny ad: