Connection pool now considered primed


#1

I’ve deployed a small application to AWS EC2, I keep getting this error:

[pool-2-thread-1] DEBUG org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - Connection pool now considered primed; min-size will be maintained

There are few mentions of this error in SOF, but not very similar to my case.

And the application does not proceed after that point.

  1. What does this error mean?
  2. What is the best way to debug this?

Thanks


#2

There is a WARN message telling you that the DriverManagerConnectionProvider is not meant to be used for production settings.

Use HikariCP, Vibur or C3P0 instead.


#3

Thanks Vlad,
What do you collect from being able to run the same code on the local machine but not on AWS EC2?
both show the same error above, but the local machine carry on with running the rest of the code.

this happens at this method :

    public List<BroadcastItem> getSent() {
        List<BroadcastItem> sentItems = new ArrayList<>();

        try (Session session = HibernateUtil.getSessionFactory().openSession()) {
            sentItems = session.createQuery("from BroadcastItem where sent = true").list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sentItems;
    }

HibernateUtil being this class:

public class HibernateUtil {
    private static final SessionFactory sessionFactory;

    static {
        try {
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            System.err.println("SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    private HibernateUtil() {
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

Because it’s a fairly simple application, looking at the [pool-2-thread-1] part in the DEBUG log makes me think that there’s also thread/connection issue? and also application does not exit when I run it from within my IDE, I have to terminate it manually.
Is there a way that you suggest to debug this further? or you still recommend switching to HikariCP or one of the others?

Thanks


#4

That’s because you don’t close the Session Factory when you are done.

Use Spring or Java EE instead. It’s easier even for small applications than writing classes like HibernateUtil and bootstrapping manually.


#5

Thanks Vlad,
Your answer led me to do more reading on the advantages of using Hibernate with Spring and EJB.

But for the sake of completing this small project though, I’ve tried to close the factorySession, this causes the application to exit completely, before the method completes it’s work.

that’s when using: HibernateUtil.getSessionFactory().close()

Is this the right use for this particular case?

As for closing the sessions, in my method above I’m using try with resources to close the session.


#6

Check out this test case template:

http://in.relation.to/2016/01/14/hibernate-jpa-test-case-template/

The JUnit test case shows you how to bootstrap, run tests, and clear resources at the end.


#7

To terminate Hibernate you have to close the SessionFactory.

Otherwise managed connection pools will do their job by design: try and keep a pool of connections open to reuse. This is essential to achieve good performance. PrepaidGiftBalance