I have two programmes. One (a C programme) writes data into a file (e.g., A) . Then the other programme (a Java programme) would read data from the file A written by the C programme.
In order to prevent concurrency problem (Java and C programmes read/ write the file simultaneously), I make the C programme create another file called .lck and the Java programme must read the .lck file first. If the .lck file exists, the Java programme tries to read the .lck file again (constantly read whether the .lck exists or not) until the .lck file is deleted by the C programme. Then the Java programme reads the data of the file A. Beside, the way how the Java programme probes whether the .lck file exists or not is done through a while loop.
Code:
// create lck file object ...
boolean doLoop = true;
while(doLoop){
if(lckFile.exists()){
doLoop = false;
}
}
It looks fine up to the present. However, I read some document saying that by using while loop would have performance implication, which is what I need to take into account. Although I have found some resources discussing the mechanism of wait-free synchronization that can be applied to such case. Unfortunately, it looks like those mechanism only provide for a single language. For example, java.util.concurrent.atomic. Moreover, the platforms currently my application runs on only support JDK1.4, which seems not support such methods. What should I do if I want to solve this problem?
I appreciate any suggestion,
Thank you very much.