java - How to avoid Concurreny from front end -


We have a requiremnt where log in to the manager site and see the list of user records in the table format. When he clicks on some record, he receives information about the user and calls the user to solve his issue. Now it is possible that two manager login and click on the same record and the same user Call at the same time. We want to avoid it.

POSITION 1: At the same time two manager login is available for both in normal color Click on green manager 1 record and start editing / calling user. In this case there should be some type lock so that the manager 2 tries to open the same record, then he will get the message 'in progress'. Status 2: View manager 1 login and records in green. Then log into Manager2 and see the same record in gray. Now he should not be able to click on that record

++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Click on the record for and update the status of the record set = 'in progress', ver_no = 1 where record_id =? And ver_no = 0 (ver_no now 1 - success)

After some time manager two login and manager 1 did not close the record, it means that the status is still in progress or it can close the browser directly. Manager 2: Select the position, record by ver_no where record_id =? (Ver_no is now 1) Click on the record to see the detail and Manager 2: Set the update record status = 'in progress', ver_no = 1 where record_id =? And ver_no = 1 (ver_no now 1 - success)

This is a good case for an optimistic locking Scenario. This will only work in backend server code. You can not lock the user by using java script on front end

Let me explain how to do this:

Add a version number column and status flag in the database table. Maybe on record table.

The manager clicks 1 on the record, first select the record from the database, increase the version number and update the flag, so that the record is now lifted.

The manager clicks 2 on the record, (if he does this on the same manager 2, then he will choose the same record selected by Manager 1) but when the manager tries to update 2 records, The version number does not match and the update will not update any rows. Use it to update your UI, which states that the record is in progress.

The conversation will resemble the following:

  Manager 1: Select the position, ver_no from the record where record_id =? (Ver_no is now zero) Manager 2: Selecting the position, ver_no record from where record_id =? (Ver_no is now zero) Manager1: Update records set status = 'in progress', ver_no = 1 where record_id =? And ver_no = 0 (ver_no now 1 - success) Manager 2: Confirm the status set to record = 'in progress', ver_no = 1 where record_id =? And ver_no = 0 (this will fail to update any row)  

At the same time they attack on the same line. Most of the time when Manager 2 selects itself, the situation will already be in progress. If you can not work with that record.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -