How to maintain data-consistency in database?

I am looking for the java code which helps me to achieve this task . The task is : I am having 1000 thread and initial value in database is 0 for a count. So I want when 1st thread executes it updates the value to 1 , then when 2nd thread executes it changes to value 2 … likewise when 1000th thread executes it update the value to 1000 . But all threads should execute simunatneously and the time taken should be as minimum as possible.