• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with File.lastModified()

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my project I use read-cache, so before every read, first of all, check File.lastModified() and then, if it differs from previous value (that I saved during previous cache update), I reload cache, otherwise read performed only from cache.
But when one application updates file using RAF (for example adds new record), File.lastModified() in other application still returns old value (while File.length() returns new length) and no cache update performed (

In case of adding new record I can solve this problem by checking modification time and length together. But in case of modifying.... ((

I already tried "rws" and "rwd" parameters of RAF constructor, but it has no effect

I can see only two ways:
1. Do not anything, because my DataFileAccessObject is Singleton and in case of network mode it will be only one instance of it. And in local mode it's very strange to have two applications with one shared db file.
2. To set last modification time by hands, by calling method File.setLastModified().

What do you thing about that?
[ October 13, 2004: Message edited by: Evgeniy Sedyshev ]
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Evgeniy Sedyshev:
In my project I use read-cache, so before every read, first of all, check File.lastModified() and then, if it differs from previous value (that I saved during previous cache update), I reload cache, otherwise read performed only from cache.
But when one application updates file using RAF (for example adds new record), File.lastModified() in other application still returns old value (while File.length() returns new length) and no cache update performed (

In case of adding new record I can solve this problem by checking modification time and length together. But in case of modifying.... ((

I already tried "rws" and "rwd" parameters of RAF constructor, but it has no effect

I can see only two ways:
1. Do not anything, because my DataFileAccessObject is Singleton and in case of network mode it will be only one instance of it. And in local mode it's very strange to have two applications with one shared db file.
2. To set last modification time by hands, by calling method File.setLastModified().

What do you thing about that?

[ October 13, 2004: Message edited by: Evgeniy Sedyshev ]



My instructions are quite explicit that only one program will be modifying the file at a time. Concurrent users of the server must be dealt with, but concurrent users of the file need not. Here's what my instructons say under locking:

"you may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple clients of your server"
 
Evgeniy Sedyshev
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, I have the same instructions
realy big thanks

but I also found one solution: I use to raf.getFD().sync() after any modifications to ensure, that data in memory and on disk are the same...
 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Evgeniy. I skip the check altogether because if it is implemented, a locking mechanism for different processes accessing the data file is necessary as well - corrupt data could result otherwise.
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Anton said, and if you update your cache in the update and create methods everything will be fine. I chose to use the cahce approach was because it was so much less code to go through a Container type than a whole file, what can I say I am lazy .
 
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic