• 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

Do you close the database (RAF) when exiting?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

do you close the database (RAF) when exiting the application?
Do we need to make it?

Thanks a lot for your comments!
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Elena Taube:
Hi all,

do you close the database (RAF) when exiting the application?
Do we need to make it?

Thanks a lot for your comments!


No I do not. I was considering to do this in finalize method but decided not to do so. More code == More bugs.
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Elena and Ali,

I think it's always a good idea to close handles to the datasources.

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ali Hussain:

No I do not. I was considering to do this in finalize method but decided not to do so. More code == More bugs.



How many bugs may be coded into


?

cheers
martin
 
Ali Hussain
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


?

cheers
martin[/qb]<hr></blockquote>
Well IMHO every single line of code has the potential to introduce bugs. So my rule is: if a line of code is not required/used in my program, I do not write it Since I was talking about the close statement in the finalize method, what if I misspelled finalize (finalise) in my code. Additionally remember the exception handling as well, so now its more than one line.

Ok jokes aside. If someone can convince me that close() is not redundant and tell when and where to close it, I might consider it myself

Anyway check this thread (second last post by Nicky Bodentien - I'm 99% sure it's redundant because Sun already put it in FileChannelImpl.finalize() for us (and RandomAccessFile uses FileChannelImpl)):
https://coderanch.com/t/185459/java-developer-SCJD/certification/When-close-RandomAccessFile


[ December 28, 2005: Message edited by: Ali Hussain ]
[ December 28, 2005: Message edited by: Ali Hussain ]
 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should consider the meaning of 'exiting', if your client side exits, it does not and cannot close the RAF, so only the actual program who opens it need to, I'm not sure what will happen if you close your program without close an opened file, do not take the risk, just close it and catch exception!

you also have to consider, for example, if you use something like RMI, provinde each client an instance of a class that can manipulate the database, if each client gets different instances, and all instances shares the same RAF, in this case, you cannot close the RAF when some clients exit (even if all clients exit), you'd better close it when Server exits, but need to carefully design your program so that clients that are still connecting won't get an ugly exception ;-)

forgive my poor English
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic