This week's book giveaway is in the Features new in Java 9 forum.
We're giving away four copies of Java 9 Revealed and have Kishori Sharan on-line!
See this thread for details.
Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Close() method  RSS feed

 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In the FBN's Data class, there is a claose method as follows:
How this method can flush any outstanding writes at the same time?
/**
* This method closes the database, flushing any outstanding
* writes at the same time. Any attempt to access the
* database after this results in a IOException.
*/
public synchronized void close() {
try {
db.close();
} catch (IOException e) {}
db = null;
}
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How this method can flush any outstanding writes at the same time?
Perhaps that's handled by
db.close();
Have you looked at the code for the db class?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12100
246
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, I can see three possibilities here:
  • this is wishful thinking on the part of the author,
  • or the author was considering a future implementation where cacheing may occur and making sure that whoever makes such a modification is aware that they will need to do any write's back to file
  • or the author is thinking of a JVM that caches the system I/O at a lower level and does a final flush and write when the file is closed


  • Since db is just an instance of RandomAccessFile, I don't see any explicit flush of data prior to the close.
    Regards, Andrew
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!