Actually, it is about transaction management. just observe it carefully.
one of your method insert a record in a table STORY, say PK of the record is 1111. after insertion and before commit, whether your conn object's auto commit is true or false, the transaction considered to be dirty. cuz you can rollback it afterwards.
Now at the same time the other
thread query that particular table to get the max of your primary key and then increment it by 1. now try to insert a new record with a max(PK)+1.
when this thread query the table to get the primary key max, it gets 1110. because the record 1111 is visible to the same DB session but not to any other. Only when your first thread commit its transaction then any other thread will get the max(pk) you want.
i hope it would be clear now.