Java Appengine:连接错误太多
我正在使用应用程序引擎和云sql,Java Appengine:连接错误太多,java,sql-server,google-app-engine,google-cloud-sql,Java,Sql Server,Google App Engine,Google Cloud Sql,我正在使用应用程序引擎和云sql, 最近,我在我的应用程序引擎错误日志上看到了这条消息 java.sql.SQLException: Too many connections at com.google.cloud.sql.jdbc.internal.E... 我在这里看到了许多相关的问题,但没有一个给出具体的解决方案。 我在我的应用程序中做了一个简单的servlet池,如下所示,我想实现一个更好的解决方案 private java.sql.Connection con = null; @O
最近,我在我的应用程序引擎错误日志上看到了这条消息
java.sql.SQLException: Too many connections at com.google.cloud.sql.jdbc.internal.E...
我在这里看到了许多相关的问题,但没有一个给出具体的解决方案。
我在我的应用程序中做了一个简单的servlet池,如下所示,我想实现一个更好的解决方案
private java.sql.Connection con = null;
@Override
public void init() throws ServletException {
con = new DbTransaction().getConnection();
}
public void doProcess(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
// Doing my task here
}
@Override
public void destroy() {
try {
con.close();
} catch (SQLException e) {
Logger.getLogger(ReceiveFeedDetails.class.getName()).log(
Level.SEVERE,
"SQL Ex con.close>> Connection Object:" + con, e);
} catch (Exception e) {
Logger.getLogger(ReceiveFeedDetails.class.getName()).log(
Level.SEVERE,
"Exception con.close>> Connection Object:" + con, e);
}
}
这是我获取连接的方法
public Connection getConnection() {
Connection con = null;
try {
DriverManager.registerDriver(new AppEngineDriver());
} catch (SQLException e1) {
Logger.getLogger(ReceiveSignupDetails.class.getName()).log(
Level.SEVERE, null, e1);
// e1.printStackTrace();
}
try {
con = DriverManager.getConnection(Configuration.CLOUD_SQL_INSTANCE);
} catch (SQLException e) {
Logger.getLogger(ReceiveSignupDetails.class.getName()).log(
Level.SEVERE, null, e);
}
return con;
}
我的代码中有什么错误吗..如何改进连接池..
请分享您的想法,如果有更好的连接池示例可用,
任何链接或示例代码请帮助……我认为您需要使用调试/配置代码来查找创建了多少连接。 正如您所展示的,我看到您希望为每个servlet创建一个连接。 -你有多少个仆人? -同时运行多少个appengine实例 连接数=servlets*正在运行的实例
这一定是因为您使用的是
jdbc:google:mysql://...
JDBC URL连接?@Razvan是的,getConnection方法中的变量Configuration.CLOUD\u SQL\u实例是CLOUD\u SQL\u INSTANCE=“JDBC:google:rdbms://...“jdbc:google:rdbms://...由旧的连接使用。请切换到jdbc:google:mysql://...
。上面的文档在这里:@Razvan感谢您提供的宝贵信息,当我切换到新的“jdbc:google:mysql”时,有什么需要我关心的吗。你能给我一个简短的回答或样品吗?再次感谢你……有一件事值得记住,那就是关闭连接是很重要的。一个appengine应用程序实例只能同时有12个连接。包含一个示例。