Win a copy of AWS Security this week in the Cloud/Virtualization 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

In Data class, how to close RandomAccessFile file?

 
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?
 
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).
 
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 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: 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
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.
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser 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.
 
Danger, 10,000 volts, very electic .... tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic