Thats my problem:
I have a table with columns: ID, VALUE and SYNCHRONICED. That last is a flag that indicates if a row has been sent to the server since the last update. I have some thread running that can access to the database
And my problem comes in that use case (with 2 threads T1 and T2:
T1-->Start_Send-->Query_Values-->Send_to_server-->wait_answer-->sync=1_for_sent_rows
T2------------------------->Update_a_row_sent
At this point T1 has tagged with sync=1 the value updated by T2.
Is there any way of avoid that problem?
- The methods for query and update are diferent so cant use synchronized at the method.
- There is no problem if T2 gets blocked until T1 ends
Thanks
Let’s say
SYNCHRONICEDis 0 when the record is inserted or updated, 1 when the record is sent to the server, and 2 when the server has acknowledged the sync.The T1 thread should do:
The
selectstatement gives the records to send to the server.Now any
insertorupdateto TAB should setSYNCHRONICED = 0;When the server responds with ack,
This will not affect any records updated or inserted since their
SYNCHRONICEDis 0.