Advertisement

05.06.2008 at 11:25AM PDT, ID: 23380442 | Points: 250
[x]
Attachment Details

Hibernate running out of connections in c3p0 connection pool

Tags: Java
Hello All,

I'm developing a web application that integrates spring 2.0, struts 1.3, and hibernate 3.0 running on centOS 5.0 with a postgresql 8.3.1 database.  I had changed from the default JDBC connection pool handler to c3p0 and have found that I exhaust my JDBC connections after 20 transactions (which is what my c3p0 max_size is set to).  I have changed this value and have confirmed that this is the configuration and value that is correlated with the behavior.  I don't think that the closed connections are being returned to the pool, or if they are, the application cannot re-open them.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Here is an excerpt from my hibernate.cfg.xml file pertaining to the c3p0 configuration:
        <property name="hibernate.c3p0.acquire_increment">1</property>
        <property name="hibernate.c3p0.min_size">10</property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.timeout">100</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.c3p0.idle_test_period">1000</property>
 
In the servlets that I coded, each Hibernate Session is initialized as the following:
 
        Session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
 
                ... misc. data accessing ...
 
        tx.commit();
        session.close();
 
As an experiment, if I do anything regarding the session after the session.close(); statement, the application throws an error sayaing that the connection has already been closed.  Therefore, it seems like the connection is being closed properly but not being returned to the pool.  
 
Here is the output once all of the connections are exhausted:
 
12:17:53,259 DEBUG [DefaultListableBeanFactory:203] - Returning cached instance of singleton bean '/actions/regLogin'
12:17:53,259 DEBUG [SessionImpl:220] - opened session at timestamp: 4956560888868864
12:17:53,260 DEBUG [JDBCTransaction:54] - begin
 
When the servlet is hit, the application hangs until the browser detects a TCP timeout.
Start your free trial to view this solution
Question Stats
Zone: Database
Question Asked By: CRSDC
Question Asked On: 05.06.2008
Participating Experts: 1
Points: 250
Views: 0
Translate:
Loading Advertisement...
05.06.2008 at 11:46AM PDT, ID: 21509821

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 12:34PM PDT, ID: 21510262

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 12:52PM PDT, ID: 21510424

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 01:17PM PDT, ID: 21510666

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 09:21PM PDT, ID: 21513145

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.06.2008 at 11:46AM PDT, ID: 21509821
make sure you close the connections when you are done with them... I faced this issue when i failed to close the connections and then connection pool was left with no more connections to return...
 
05.06.2008 at 12:34PM PDT, ID: 21510262
I'm ensuring that i have a session.close(); statement at the end of the servlet.  Is there anything else that I have to do to close the connection?
 
05.06.2008 at 12:52PM PDT, ID: 21510424
try

SessionFactory's getCurrentSession(); method instead of openSession...


or

use

before closing the session.
    session.flush();
 
05.06.2008 at 01:17PM PDT, ID: 21510666
Thanks for the response,

I've already tried the getCurrentSession() method and it says that the current session is closed.  I have also tried inserting the session.flush(); method before closing the session and that does not help either, unfortunately.
 
05.06.2008 at 09:21PM PDT, ID: 21513145
It appears that my error wasn't in the servlet that was being executed, but in the JSP that followed.  I was not properly committing and closing my session there.  Thanks for your feedback!
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628