Dear Jon:
----------------------------------------------------------
You mean makes the DataAccess class singleton
----------------------------------------------------------
No - what happens if you add extra tables to the database?
Maybe in another words, how many RandomAccessFile object can actually access
database file?
ps. In SCJD exam, database = database file = only one table
--------------------------------------------------------------------------
synchronize all data access method?
--------------------------------------------------------------------------
No - just synchronize the code that needs it, wether that be a method or blocks of codes in methods.
agree with you.
----------------------------------------------------------------------------
why we needs the APIs
lock(recNo)
unlock(recNo)
isLock(recNo)
---------------------------------------------------------------------------
You are just providing a mechanism for clients to declare that it wants exclusive delete and update rights to this record. It is up to you to code clients to honour this convention. This has no relation to writing thread safe code.
if update() is synchronized, ClientA update 1'th record, and at the
same moment ClientB update 1'th record.
either ClientA or ClientB can get "synchronized", if ClientA
get "synchronized", ClientB are blocked in synchronized pool until
ClientA release the "synchronized". so there is no need to call
lock() before update(), because this is all done implicitly.
thanks sincerely,
Ching-Tien Chang
[ July 14, 2004: Message edited by: Ching-Tien Chang ]
[ July 14, 2004: Message edited by: Ching-Tien Chang ]