Please tell me why do we all require locks when the db is synchronized for add, delete, modify, find and seek. At any point of time, db is used for only one purpose. When there is a modification taking place in db,all other threads are waiting for thier operation. Hence, is'nt lock/unlock redundant?
From the first (superficial) look, the lock/unlock methods are, indeed, redundant. However, if you think it through, the locks are neccessary to implement a business requirement that any particular client may not book more seats than available for the flight. Think of this scenario in this particular order:
Remote
ClientA checks to see how many seats are available, -- there are 2 available
Remote
ClientB checks to see how many seats are available, -- there are 2 available
Remote
ClientA invokes the modify() method on Data and reduces the seat count in database to 0.
Remote
ClientB invokes the modify() method on Data and reduces the seat count in database to -2 (oops!).
To solve this problem, you need some
inter-client synchronization, i.e, a server side semaphore.
Eugene.