In my current code, every read, update, create, find, and delete operation requires me to use RandomAccessFile to access the database flatfile. Part of the reason why I went with this approach is because I knew that upon server shutdown, the database file would be up-to-date with the latest information since all update/delete/create operations immediately access the flatfile.
However, I do not like having to handle IOExceptions with each read/write operation, so I was thinking of reading the database into memory once, and having all read/write operations interact with the database copy in memory. Then, when the server is shutdown (VM terminates), I would have it persist the data to the database file.
Is the first solution ok (how should I handle IOExceptions)? I like the second solution better, but I am worried about problems occurring as I write data to the hard drive in the shutdown hook
thread.
What do you think?