I'm solving the concurrency issue by using a third dummy table where each thread will first try to insert its unique data as a record and then proceed with whatever it wants to do.
This dummy table's primary key are set of columns which map one-to-one with all the unique data a thread holds.
If concurrent threads try to insert into this dummy table then only one insert will succeed (because of primary key constraints).