• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

In Data class, how to close RandomAccessFile file?

 
Jianping Wang
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my assignment, the DB interface does not have "open" or "close" method. I open the RandomAccessFile in constructor, but how to close it?
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I extended DB with my own interface, that adds close(), and Data implements my own interface (but also DB by transition).
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will do the trick. Or you could use some kind of shutdownhook where you close the RandomAccessFile.
 
Jianping Wang
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
some kind of shutdownhook

What's that???
Can you give me an example? it has something to do with template method design pattern, right?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you already try google? Or the search engine of this forum? I'm sure you'll find plenty of examples! ShowSomeEffort please.
 
Jianping Wang
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that, I thought shutdownHook only mentioned in some kind of book.
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jianping Wang wrote:Sorry about that, I thought shutdownHook only mentioned in some kind of book.


Shutdown hook? I used it in my assignment when I blablabla so that the RandomAccessFile closes "properly". Guess what the blablabla refers to?? A big hint: think server.
 
Jianping Wang
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you shutdown the server. During the shutdown process, the ShutdownHook will be called to close RandomAccessFile.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic