• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RandomAccessFile rws mode

 
Kevin Mc Cusker
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I open the file in this mode does it mean I dont need to call Close() on it since the data is getting wrote to file?

Thanks.
 
Peter Jakobsen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should always close your files, when you're not using them anymore, to release file pointers. Is there any reason that you don't want to close the file?
 
Kevin Mc Cusker
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
No reason, but i think the only place i could do it is in the finalize() method of my data class. as far as i am aware this is pretty dodgy so was hoping i wouldnt need to do call close() at all.
Is the risk of the finalize not being called large? What are the consequences of implementing it this way?
Is there another way of safely doing this on server shutdown?

Thanks
 
Daniel Massie
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you create an extension to the provided database interface, you could provide a shutdown hook which will close the file. You'd then reference this new interface throughout the application rather than the provided one.
 
Kevin Mc Cusker
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A shutdown hook? Time for some investigating!!

Thank You all for your replies!
 
Daniel Massie
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry if that was confusing, I just meant a method that you would call when the application was shutting down.
 
Adam Nace
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shutdown hook?!

just create the random access file outside of your Data object, and pass it in as a construction parameter. Then you can close it any time you want.

- Adam
 
Daniel Massie
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which then means that its not only your data class (and any classes that it delegates to) that knows that its a file based implementation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic