简体   繁体   中英

Database connection handle issue

I am currently doing testing with Google Search Appliance (GSA) for crawling database and built a connector for handling database query and stuff.

The GSA have a crawl interval, which mean it will repeatedly crawl the database for update. So my question is:

  • Should I create a connection and close it for everytime GSA crawl the database ? (The crawl rate is very high, which mean connection will be repeatedly created and close alot).

  • Or should I just create a connection and let it stay to query the database for every crawl? The problem is that I do not have anyway to close the connection when the system terminated.

Or another better option ?

Use connection pooling as Vikdor said, but I would suggest you use BoneCP as it is better performance wise. Set a number of connections in the pool and then you would not have to worry about opening and closing or keeping the connection alive.

You should employ a simple connection pooling library like C3P0 and configure the number of connections as per your requirement. The connection life cycle management will be handled by the library and you will relieved from connection establishment, dropping them during inactive periods, re-establishing when needed etc.,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM