Problem with Java Parallel thread processing and status update on DB

Here's the sample code/Flow Diagram:-

Eg: status code = Status -> 0021=Delivery completed, 0019= On long haul, 0020=At final distribution centre.

...

for (.....)

{

if sOldStatus = 0021

{

ignore upadte;

continue

}

else

call changeStatus

}

Thread1, incoming update status=0021, Time:18:22:22.23

Thread2, incoming update status=0020, Time:18:22:22.24

Java Code gets gets current status from DB = 0019(API call). If DB status = 0021 ignore any update else Calls changeStatus.

Result: The status is changed first to 0021 and then to 0020(as both threads have the current DB status as 0019).

Query: Is there any way to avoid an update to status in DB after the status is changed to 0021? One method is using single thread. But it抯 not feasible due to heavy load.

[871 byte] By [Simhama] at [2007-11-26 14:43:40]
# 1
Synchronize the method that does and checks the update.
abillconsla at 2007-7-8 8:31:18 > top of Java-index,Java Essentials,Java Programming...