0

I've app, which use the database in multiple concurrent sessions (over 1000). In Postgres the max connections available is set to 100 by default and i haven't change this.

Hibernate has max connection pool size is 20, but the app seems to be ignored this and throws "Too many connections" error.

So the problem is how to handle over 1000 sessions when the only available is 100? Is there queue or smth like this is possible?

1 Answer 1

2

Hibernate has max connection pool size is 20, but the app seems to be ignored this and throws "Too many connections" error.

Double check your use of Hibernate Session Factory:

  • in case your is a web app read this [1]
  • in case your is a standalone app read this [2]

Often the problem is the bad usage of Hibernate Session.

[1] https://developer.jboss.org/wiki/UsingHibernatewithTomcat [2] http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch01.html#tutorial-firstapp-workingpersistence

So the problem is how to handle over 1000 sessions when the only available is 100? Is there queue or smth like this is possible?

100 are the concurrent connection that you can open, over these you can do more than 100 operations: Hibernate just manage the queue for you.

Sign up to request clarification or add additional context in comments.

4 Comments

I took the [2] case and have changed .openSession() to .getCurrentSession();.. etc, as it described there. But there's no effect. In the app every session creates from different threads at the same time (1000 threads=1000 sessions) and .getCurrentSession() creates new one session anyway like .openSession() does. In this case, ofc 1000sessions will hit over db connection restriction and the error will be thrown. Thats why i want to queue this. But Hibernate seems dont want to manage this for me :(
I tried to open the session once and nest the threadpool to this, but it seems to be bad idea because of Hibernate doesn't support nested transactions error
You have used the singleton as there? docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/…
Yes i used it as there. But now i've fixed an error by using c3p0 connection pool and setting the max pool size to 100. Works fine now :)) Thanks for help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.