A is a table
a1 is a primery key in A
a2 is another field in A
I have created a java web based application and deployed in wildfly server. The field a1 is a readonly field to the enduser and it will show the maximum count of the rows in table A and a2 is an editable field. Now consider two end users are acessing this application at same time and trying to insert data into the table A. Both these users will see the same value for field a1 and give different values in the field a2. Now both the users submit the application and will insert data into A. This will result in inserting two rows with the same value for the field a1. But the field a1 is a primary key. So it should have distinct values.
How can I prevent this while inserting data in table A? Here do we need to apply threading concept?