我正在使用具有以下配置的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.我的猜测是客户端过于频繁地发送请求,在返回池之前打开许多连接,因此池中没有任何连接。
我无法控制客户端连接的频率。是否需要更多配置来处理这种情况?