Hi guys.

I have a Java program that works in 3 stages after connecting to a MySQL database to give desired results.

The first stage involves a function X that returns a value it finds in table A or zero.

The second stage involves a function Y that's only allowed to run if function X returned a numerical value other than zero.It checks table B for a duplicate entry of the returned value.

The 3rd stage involving Z: if there's an existing value in table B equal to the returned value, it returns the string "Duplicate entry.Please enter another value", else it inserts the value in an appropriate column VALUES in table B and calculates a total value, which it then inserts into column RUNNING TOTAL in table B as well.

Now my problem, which I noticed happens on occasions,( say like 2% of all transactions) whose circumstances are unclear is this: that in some cases, it seems that in table B I have duplicate entries of the same value!!Even to the extent that the time stamp associated with each entry is the same to the date and time(example, 2011-01-31 12:20:20 for like 6 entries).Is there something to do with how Java access to MySQL is supposed to be done which I am overlooking, or maybe a MySQL installation or tweaking feature?
98% of transactions work well within the logic of the 3 stages!!
Kindly assist if possible and know that any help will be greatly appreciated!
Thank you all

Probably just simply two different instances of the program running at the same time. A so-called race-condition. Both checked table b and did not find a record and so both added it.

Probably just simply two different instances of the program running at the same time. A so-called race-condition. Both checked table b and did not find a record and so both added it.

Oh!How does this come about, or is it because I'm employing the use of threads?

Thanks Masijade

Could be two different clients, could be two different threads, could be a few things. From the way this sounds it should be "achievable" with a single sql statement which should elimanate the race-condition possibility.

Probably just simply two different instances of the program running at the same time. A so-called race-condition. Both checked table b and did not find a record and so both added it.

Thanks masijade for your insightful contribution which has reminded me of issues related to multi-threaded applications.

Sorry, let me correctly say that I am using threads in other modules of the same application but not in this particular module of the application.Your comment that it could be copy of the same program running, seems more likely.Could it be that Linux boxes here could have a cached copy of the application running, even if one attempts to stop-then-start a java cron job?Just thinking loudly.

This article has been dead for over six months. Start a new discussion instead.