Mysql 冬眠池太快耗尽

Mysql 冬眠池太快耗尽,mysql,hibernate,transactions,connection-pooling,dropwizard,Mysql,Hibernate,Transactions,Connection Pooling,Dropwizard,我正在使用以下配置开发dropwizard应用程序 database: driverClass: "com.mysql.jdbc.Driver" user: "root" password: "mypassword" url: "jdbc:mysql://mysql:3306/?autoReconnect=true" properties: charSet: "UTF-8" hibernate.dialect: "org.hibernate.dialect.M

我正在使用以下配置开发dropwizard应用程序

database:
  driverClass: "com.mysql.jdbc.Driver"
  user: "root"
  password: "mypassword"
  url: "jdbc:mysql://mysql:3306/?autoReconnect=true"
  properties:
    charSet: "UTF-8"
    hibernate.dialect: "org.hibernate.dialect.MySQLDialect"
    hibernate.hbm2ddl.auto: "create"
    hibernate.show_sql: true
  maxWaitForConnection: "1s"
  validationQuery: "/* MyApplication Health Check */ SELECT 1"
  minSize: 8
  maxSize: 32
  checkConnectionWhileIdle: true
  checkConnectionOnReturn: true
  checkConnectionOnBorrow: true
我有以下交易

@Transactional
    public void createOrSave(Service service) {
        Service existingJar = getById(service.id);

        Session session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        try {
            if (existing != null) {
                session.merge(service);
            } else {
                session.save(service);
            }
            tx.commit();

        } catch (RuntimeException e) {
            tx.rollback();
            throw e;
        } finally {
            session.close();
        }

    }
以及其他性质相同的交易。池很快就会耗尽,服务器开始返回500。我的猜测是客户端发送请求太频繁,在返回池之前打开了许多连接,因此池中没有剩余的连接


我无法控制客户端连接的频率。是否需要更多配置来处理这种情况?

尝试使用flexypool并在测试时设置参数#Askhibernatevlad您有没有示例?我只在搜索itcheck时才找到maven插件。我应该查看codehale metrics还是c3p0?您是否需要@Transactional注释并在方法中手动处理事务?我原以为只需要其中一个