Solved

FATAL: sorry, too many clients already

Posted on 2010-08-16
4
1,422 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

757 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