Solved

FATAL: sorry, too many clients already

Posted on 2010-08-16
4
1,462 Views
Last Modified: 2013-12-22
I am using a reusable EntityManager design, similar to
http://blog.julianpaas.com/?p=65

according to this approach, the EntityManager is kept alive (does not call em.close), so it is reused within a thread.

after running my program for a while, I start to get

org.postgresql.util.PSQLException: FATAL: sorry, too many clients already

I am wondering if this is due to the fact I don't call em.close, and some how, too many threads ended up using too many connections.

It is a big change if I add in em.close every where. I wonder if someone can give me a tip whether this is the area of suspect, or there is some other way I can resolve this out of connection error.

I am using c3p0 connection pooling with max_size set at 20.
0
Comment
Question by:bhomass
  • 2
4 Comments
 
LVL 10

Expert Comment

by:Hegemon
ID: 33454085
in J2EE environment Entity Manager will automatically close at the end of your EJB method.
If you open it manually / not use it in EJB methods, you have to close it manually as well.
0
 
LVL 10

Assisted Solution

by:gordon_vt02
gordon_vt02 earned 70 total points
ID: 33454496
Check your database configuration and make sure the maximum connections are set high enough to support your application.  Are there any other apps using the database at the same time?  If so, make sure the connection limit can support all of them.
0
 

Author Comment

by:bhomass
ID: 33456128
can I ask if I call em.close(), does that guarantee to close the db connection?
0
 
LVL 10

Accepted Solution

by:
Hegemon earned 180 total points
ID: 33456144
In a managed J2EE environment (EJB) this will produce an exception.
In a non-managed environment, which I suspect is what you have, yes, it will release the connection and return it to the pool.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
network + 7 80
Free Alternative to JIRA 4 91
Java passing arguments (type error) 2 48
ArrayIndexOutOfBoundException 9 68
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now