Posted By:
Zac_Jacobson
Posted On:
Thursday, September 12, 2002 12:34 PM
Instead of synchronizing the entire method, you need to have synchronized enter and exit methods that get accessed from your write method. Also, make sure that the code to change the variable back to "unlocked" is in a finally block that belongs to a try block which contains the enter method.
- Enter write method
- Enter synchronized enter method
- Is file marked as being locked?
Yes:- throw exception
No:- Mark file as locked
- Write to file
- Enter synchronized exit method
- Make file as being unlocked