jfinal中如何设置连接数据库失败重试次数等

以下我看DruidDataSource 是提供了这样的方法,请问jfinal中如何设置。

DruidDataSource druidDataSource = new DruidDataSource();

// 失败后重连的次数

druidDataSource.setConnectionErrorRetryAttempts(3); 

// 请求失败之后中断

druidDataSource.setBreakAfterAcquireFailure(true); 


评论区

mekain

2023-03-30 11:02

DruidDataSource 默认是无限重连,导致服务卡死。

杜福忠

2023-03-30 18:12

DruidPlugin dp = new DruidPlugin(...){
@Override
public boolean start() {
super.start();
ds.setConnectionErrorRetryAttempts(3);
ds.setBreakAfterAcquireFailure(true);
return true;
}
};

mekain

2023-03-31 10:12

@杜福忠 我刚看了,DruidPlugin里边没有start这个
DataSource ds = new DataSource() {

@Override
public T unwrap(Class iface) throws SQLException {
// TODO Auto-generated method stub
return null;
}

@Override
public boolean isWrapperFor(Class iface) throws SQLException {
// TODO Auto-generated method stub
return false;
}

@Override
public void setLoginTimeout(int seconds) throws SQLException {
// TODO Auto-generated method stub

}

@Override
public void setLogWriter(PrintWriter out) throws SQLException {
// TODO Auto-generated method stub

}

@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
// TODO Auto-generated method stub
return null;
}

@Override
public int getLoginTimeout() throws SQLException {
// TODO Auto-generated method stub
return 0;
}

@Override
public PrintWriter getLogWriter() throws SQLException {
// TODO Auto-generated method stub
return null;
}

@Override
public Connection getConnection(String username, String password) throws SQLException {
// TODO Auto-generated method stub
return null;
}

@Override
public Connection getConnection() throws SQLException {
// TODO Auto-generated method stub
return null;
}

};

杜福忠

2023-03-31 17:32

@mekain 不可能没有,这个是Plugin插件都有的方法。看下是不是看错包了,注意是JF包里的这个类

山东小木

2023-04-05 18:20

@jfinal 里暴露一下这个设置也行吧

热门反馈

扫码入社