File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about datasource close?

 
daming wang
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I have a question about close the datasource, as we know that if you don't close the connection, will cause big error. But who could tell me that if I forget close the datasource, what will happen? do harm to my application for the database server? thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33716
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It won't harm the database server, but it will likely cause a resource leak. Calling close() returns the connection to the pool. If you skip the call, the pool doesn't know it can give that connection to others until the connection times out.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only need one DataSource, so it is reasonable to obtain it once and cache it in a static variable. The DataSource is thread-safe, so it can be used simultaneously by any of the requesting threads.

It is very unlikely that there will be any problems arising from keeping one DataSource open.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33716
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ignore my response. I misread the question and answered about closing connections.

I agree with Roger that it is not necessary to close the data source. On an application server, the server often manages the data source anyway, so it stays open.
 
daming wang
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's ok, thank you all, Roger, Jeanne.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic