I want to make sure that I correctly implement a record locking stategy, satisfying this requirement:
Your server must be capable of handling multiple concurrent requests, and as part of this capability, must provide locking functionality as specified in the interface provided above. You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server. Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available
To
test this, I instantiate the class Data:
Then I instantiate a class (DBRead) that is derived from class
Thread that has the following run method. During instantiation, I specify the Thread's name and what record number I want to read:
Then I instantiate another class (DBCheck) that is derived from class Thread that has the following run method:
I put both these classes in a loop:
Then start 'em up:
If I create enough threads I see records initially locked, then eventually these records get read.
Is this a valid way to simulate many "nearly-concurrent" requests to the database for the same record, in order to validate the record locking algorithm?
Any comments are welcomed.
- Rolf.