I am trying to upgrade a project from Java 7 to Java 8 and cannot seem to get c3p0 to handle the migration. It appears that c3p0 is getting stuck waiting for a connection to MySQL and so my web application just hangs forever when it hits line 1459 in the BasicResourcePool class: 'this.wait(timeout);'. My project runs fine in Java 7. I have tried updating the MySQL-connector jar to 5.1.33 and have updated c3p0 to 0.9.5-pre9.
I can only assume that Java 8 changed JDBC connection handling and thus I need to change something. This is how I am setting up the MySQL connection. I have verified that all of the values from the property file are being grabbed correctly.
properties = Locator.getInternalProperties(Locator.MYSQL_PROPERTIES);
cpds = new ComboPooledDataSource();
cpds.setDriverClass("com.mysql.jdbc.Driver");
cpds.setJdbcUrl("jdbc:mysql://" + Locator.getValue(properties, Locator.HOST) + "/"
+ Locator.getValue(properties, Locator.SCHEMA)
+ "?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&characterEncoding=UTF-8");
cpds.setUser(Locator.getValue(properties, Locator.USER));
String password = EncryptionUtils.decrypt(Locator.getValue(properties, Locator.PASSWORD));
cpds.setPassword(password);
cpds.setMaxPoolSize(50);
cpds.setMaxStatements(200);
cpds.setIdleConnectionTestPeriod(60);
cpds.setPreferredTestQuery("SELECT 1");
I am not sure what else I can try at this point.
Here is a thread dump from Java 8:
"http-bio-8080-exec-9@8497" daemon prio=5 tid=0x52 nid=NA waiting
java.lang.Thread.State: WAITING
at java.lang.Object.wait(Object.java:-1)
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1459)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:639)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:549)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:756)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:683)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
at com.attensity.saascore.shared.dao.BaseDao.getConnection(BaseDao.java:24)
at com.attensity.saascore.shared.dao.UserDao.getUserByUsernameAndPassword(UserDao.java:46)
at com.attensity.saascore.shared.manager.UserManager.getUserByUsernameAndPassword(UserManager.java:92)
at com.attensity.saascore.shared.manager.AuthenticationManager.authenticateUser(AuthenticationManager.java:60)
at com.attensity.saascore.rest.user.service.AuthenticationService.authenticate(AuthenticationService.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
- locked <0x2478> (a org.apache.tomcat.util.net.SocketWrapper)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
It appears my issue has to do with Java 8 and localhost for MySQL. I created a new super simple project to test c3p0. Again, Java 7 worked without issue but Java 8 did not. I then created a super basic JDBC application and Java 7 worked and Java 8 did not but I could actually see an error saying that my connection was refused. c3p0 is not handling the connection refused appropriately so the connection thread is just hanging forever. I did in fact test that by just letting my application run overnight to see if I eventually get a connection timeout in c3p0 but I did not.
Finally I created a user connection in MySQL using 127.0.0.1 instead of localhost and changed my connection URL to be 127.0.0.1 and magically my JDBC test worked. I then tested c3p0 with the 127.0.0.1 connection and it worked. I did not dig into why localhost works fine in Java 7 but not Java 8. Hopefully changing localhost to 127.0.0.1 in my production environment for MySQL will not be an issue.
If you would like me to help troubleshoot anything or do more testing I would be happy to do so. For now I am going to move on. Hopefully someone smarter than me has a better solution.