当我离开页面 10 分钟然后刷新或快速刷新页面多次(当然是控制器启动查询的页面)时,我收到此错误。
Tahe 与此处相同的错误:https ://github.com/javalite/activejdbc/issues/268
我使用 ActiveJdbc 的 1.4.13.j7 和 c3p0-0.9.1.2 作为连接池。
这是我的代码:连接的单例
import com.mchange.v2.c3p0.DataSources;
import java.sql.SQLException;
import javax.sql.DataSource;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ConnectionPool {
private DataSource dataSourceUnpooled;
private DataSource dataSourcePooled;
private static ConnectionPool instance;
private ConnectionPool() {
init();
}
public static synchronized ConnectionPool getInstance() {
if (instance == null) {
instance = new ConnectionPool();
}
return instance;
}
private void init() {
try {
Class.forName("org.postgresql.Driver");
dataSourceUnpooled = DataSources.unpooledDataSource("jdbc:postgresql://127.0.0.1:5432/mydb", "postgres", "");
dataSourcePooled = DataSources.pooledDataSource(dataSourceUnpooled);
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(ConnectionPool.class.getName()).log(Level.SEVERE, null, ex);
}
}
public DataSource getConnection() {
return dataSourcePooled;
}
}
这是一个抛出异常的控制器示例
Base.open(ConnectionPool.getInstance().getConnection());
List<Game> games= Game.where("add_on_id = ?)", addOnId);
games.size();
Base.close();
return "addOnView";
我看到有人在网上搜索解决方案时也遇到了这个问题,但我没有找到任何人解决它。我使用open和close,所以我不知道问题出在哪里。
有什么我做错了吗?
编辑:
这是整个 statcktrace
HTTP 状态 500 - 请求处理失败;嵌套异常是 org.javalite.activejdbc.DBException:无法打开新连接,因为现有连接仍在当前线程上,名称:默认值,连接实例:com.mchange.v2.c3p0.impl.NewProxyConnection@50ed26eb。这可能表明您的应用程序中存在逻辑错误。
类型异常报告
消息请求处理失败;嵌套异常是 org.javalite.activejdbc.DBException:无法打开新连接,因为现有连接仍在当前线程上,名称:默认值,连接实例:com.mchange.v2.c3p0.impl.NewProxyConnection@50ed26eb。这可能表明您的应用程序中存在逻辑错误。
描述 服务器遇到一个内部错误,阻止它完成这个请求。
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.javalite.activejdbc.DBException: Cannot open a new connection because existing connection is still on current thread, name: default, connection instance: com.mchange.v2.c3p0.impl.NewProxyConnection@50ed26eb. This might indicate a logical error in your application.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
com.myapp.config.ActiveJdbcFilter.doFilter(ActiveJdbcFilter.java:46)
root cause
org.javalite.activejdbc.DBException: Cannot open a new connection because existing connection is still on current thread, name: default, connection instance: com.mchange.v2.c3p0.impl.NewProxyConnection@50ed26eb. This might indicate a logical error in your application.
org.javalite.activejdbc.DB.checkExistingConnection(DB.java:235)
org.javalite.activejdbc.DB.open(DB.java:186)
org.javalite.activejdbc.Base.open(Base.java:106)
com.myapp.controllers.AddOnController.addOns(AddOnController.java:145)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:483)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
com.myapp.config.ActiveJdbcFilter.doFilter(ActiveJdbcFilter.java:46)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.27 logs.