Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

No shutdown hook?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Is it possible to use a cache for the assignment and not to implement a shutdown hook. My approach is-
I have a DBFileAccess class with two method to load the database records into a cache and a persist database method to load the cache into the database file. For this, in my load Database method -


For persist Cache to Database file


My Data class is Singleton, with all methods synchronized and at application startup, in Data class private constructor, I call the loadDbRecords from the DBFileAccess class.
After each update, delete or create operation I persist database records back to the file instead of persisting records at the time of server shutdown. My server shutdown is simply System.exit(0) as my RandomAccessFile is closed after each read and write. Is this a valid approach to pass the exam? I know there will be slow performance issues but as it is not a criteria in this exam, can I overlook it? Any advise in this direction highly appreciated.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a valid approach. Not the most performant one, but that's not a must requirement. The only question I can think of: why using a cache if you write each time to the database file?
 
Bably Das
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As always thanks a lot Roel for your quick reply.

The only question I can think of: why using a cache if you write each time to the database file?



Being a junior Java programmer myself I find working on a cache easier than the actual file itself.

Thanks,
Bably Das
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of the ideas I've thought about. The rationale as I saw it is that you only take the performance hit on data writes. Data reads are likely to be much more common, so you really want those to be faster. So, you load the entire database into the cache at startup, and then write changes to both the cache and data file. But you never read from the file after the initial load.

I still haven't decided for certain yet (though I'm leaning towards the "write on shutdown" approach).
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matthew,

Great argumentation

Just a remark: in a (room) booking system I guess there will be significant more updates than when your database file contains customers (with name, address, phone numbers,...). But of course the number of reads would still outshine the number of writes.

Kind regards,
Roel
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Roel De Nijs wrote:Hi Matthew,

Great argumentation


Thanks! .

For completeness - the advantage (as I see it) of the continuous writing is that you don't lose all your data changes in the event of a crash. I also considered a compromise approach (periodic asynchronous writing of changes), but ruled that out as too complex for this exercise (I'd be tempted to do that or some other sort of autosave feature in a 'real' project though).

Whatever I decide, all this is going in my choices.txt file!
 
So I left, I came home, and I ate some pie. And then I read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic