The platform for our application is Java 1.4.2. We need to run certain certification applications on this version of JVM (embedded system).
One of these applications is creating a thread T1 which updates a file (by writing to it) and another thread T2, which is supposed to read the updated contents(T2 is always launched after T1).
The problem is that the writing thread T1 is getting delayed and reading thread T2 is reading incorrect data. The thread T2 doesn't check whether contents of file were updated or not.
The delay causing factor can be assumed to be not fixable for the purposes of this discussion. We cannot change the application, but we can change the JVM and the native layer interface.
Please suggest solutions to serialize access to the file without changing the application. Also, please critique the following approach for feasibility: Create a look ahead thread in JVM which can analyze java byte code and serialize access to a file across multiple threads of the same application.