JDBC hanging upon connection
Posted by: James Coster
Date: May 21, 2012 08:22AM

Hi,
I'm running connector 5.1.20 on Ubuntu 11.10.

~# java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

I have the following code in a jar file:
--
Connection conn = null;
try
{
System.out.println("Init JDBC driver...");
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
System.out.println("Getting connection from DriverManager...");
conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1/<DB>?user=<USER>&password=<MYPASSWORD>");
System.out.println("DB connection opened successfully!");

}
catch (Exception ex)
{
ex.printStackTrace();
}
--

20% of the time, the above code works fine, as expected; a connection is established, no errors. However, the other 80% of the time the code hangs on "Getting connection from DriverManager...". No exceptions, nothing, even for 20+ minutes. I can't ctrl + c out; the thread has hung.

jstack output:
--
"main" prio=10 tid=0x0000000041b3c800 nid=0x17fc runnable [0x00007feb60ca5000]
java.lang.Thread.State: RUNNABLE
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
- locked <0x00000000f3230390> (a sun.misc.Launcher$AppClassLoader)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
- locked <0x00000000f3230390> (a sun.misc.Launcher$AppClassLoader)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at DBTest.<init>(DBTest.java:23)
at DBTest.main(DBTest.java:11)
--

Someone has suggested it could be to not releasing connections, but it can happen the first time after reboot so it can't be that...

Has anyone got advice? The above code is a standalone jar I've created to try to troubleshoot this issue, there's nothing else going on.

Any help greatly appreciated...
Cheers.

Options: ReplyQuote


Subject
Written By
Posted
JDBC hanging upon connection
May 21, 2012 08:22AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.