• 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

NX: DB connection close Vs keep it open

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I completed my project and presently testing/refactoring the code. One of the things I am debating about is whether to close the db file for every read/write or to close it when closing down the server.
I have implemented my solution using RMI and there is a single db instance for all the clients. It seems to me like in a multi user/single data environment, it would result in better performance in closing the connection in the end.
Presently I am closing the db file, when I close the connection but I was wondering if there any pitfalls in this approach.
Any comments?
Thanks,
Raj
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raj,
I don't know if I can answer you, but I do not understand why you need to close the DB connection for each read/write?
Either way should work for SCJD, I guess. Please correct me if I'm wrong.
Thanks.
 
Raj Shekhar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Satish,
I guess it is a tradeoff between overhead associated with opening a connection vis a vis Resources consumed. As the impact of this choice is mainly on performance, you are correct to say that this is not very relevant for SCJD for which performance is not a requirement.
However, I want to be in a position to defend my choice in the documentation and/or essay exam and wanted to see if am making the right assumptions.
thanks,
Raj
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks man. Actually I also wanted to mention that its an performance issue, but thought I was'nt smart enough to say that
Good Luck to you.
 
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raj,

Originally posted by Raj Shekhar:
Hi all,
Presently I am closing the db file, when I close the connection but I was wondering if there any pitfalls in this approach.
Any comments?


I don't see the benefit of opening and closing the file more than a single time. Closing the file when the connection is closed is fine. We're not talking about a lot of resources, but rather just one file handle. What you're already doing is fine. I'm having trouble seeing what problem is solved by changing the code to close the file after every read or write. Maybe I'm missing the problem you're trying to solve.
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raj,
If you completed your project, I wouldn't change that now. I guess that everything works, so why taking any risk in such a refactoring?
Opening/closing the file connection for each access is what Max himself does in his great SCJD book. It's highly defendable because - as you state yourself - performance is not a requirement in this assignment.
Honestly, it's even better if you don't change anything. Your solution is slow (but it's not an issue) but scalable (a quality). If you don't use NIO (and there are now compelling reasons to not choose NIO ), and wants to keep your design simple, you'll have to keep one connection open per client, which is not scalable at all (remember that RAF is not threadsafe). An alternate solution would be to implement a RAF connections pool, but I think it's out of scope of this assignment (though I'm now experimenting it, just for the fun ).
Regards,
Phil.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi George,

I'm having trouble seeing what problem is solved by changing the code to close the file after every read or write.


My post crossed yours, and it looks like I inverted the question... I understood that Raj opened/closed the RAF connection for each access.
BTW Raj, are you using NIO ?
Best,
Phil.
 
Raj Shekhar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
George, Phillip,
Thanks for your clarifications. I was hoping to confirm that my assumptions were correct and that I did not miss anything.

Thanks,
Raj
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic