Hi all
I'm working on my
SCJD assignment and I'm thinking about some way to ensure that no one is accessing data file when someone else is shutting down the database. I've found method DvdFileAccess.setDatabaseLocked() in Andrew's code. CleanExit.run() javadoc states "It ensures that the database is in a clean state for shutdown (that is, there are no outstanding writes occuring)", but I'm not sure how this is ensured.
Consider this scenario. Only 2 threads are working.
Thread A wants to create new record, persistDvd() method is invoked, Thread A gains the write lock, updates recordNumbers and then releases it (note that it may be still in persistDvd() method). At this point Thread B is shutting down the database, setDatabaseLocked() method is invoked, Thread B gains write lock since Thread A already released it, JVM terminates with Thread A still in persistDvd method (perhaps writing to file).
Am I missing something?