I am almost ready to upload my assignment, but felt that there may be an issue.
I have a business-tier method of bookRoom which does the following logics:
db.lock
db.update
db.unlock
Suppose I have two threads A and B trying to update DB at the same time. While
thread A invokes bookRoom for client A, thread B calls bookRoom as well. So thread B goes to sleep, relinguish CPU, and such. After thread A finishes update by writing an owner ID (i.e. 111) to DB and unlocking, thread B gets lock and should be able to update DB by writing another owner ID (i.e. 222) to DB.
Now if client A tries to search all records, A will be surprised to find that he/she did not get room booked. Should I allow such scenario to happen.
I implemented a way of not allowing a "booked" record to be updated again in my GUI. When a client selects a record in JTable which has a valid owner ID, I simply disable the owner field. Only empty owner field in JTable is allowed to enable owner text field for booking. I implemented validation check for owner text field to check if user's input is digit and only 8 digits is maximally allowed. But this still may have drawback. What if a client changes his mind to cancel his booking/reservation?
However, if I allow repeated updating no matter if a record has booked as indicated by a valid owner ID, this seems undesirable also.
Please enlighten me