jvm initialization takes 3 minutes?

Hi,

I have a problem that appears to be associated with jvm start up. I am running SuSE linux v9.0, Spring V1.1.3, Tomcat v5.5.6, jdk 1.5.0 , mysql-standard-4.0.21. My jdbc drivers are (both work with the same results): com.mysql.jdbc.Driver or org.gjt.mm.mysql.Driver contained in mysql-connector-java-3.0.16-ga-bin.jar.

The reason for the preamble is that when I try to connect to a mysql daemon using hibernate the session hangs for 3 minutes. At first I blamed hibernate. However, I found that this long init time always occurred whenever a new jvm was used, either from the command line, my IDE, or ant. So I decided to profile the hibernate test app and see where the hangup was. I ran the following command from the shell:

java -client -Xprof -Xmx512m org.appfuse.hibernatetest.UserCreateTest

These were the results

Flat profile of 190.97 secs (17211 total ticks): main

Interpreted + nativeMethod

99.2%0 + 17066java.net.PlainSocketImpl.initProto

0.1%16 +3java.lang.ClassLoader.defineClass1

0.0%0 +3java.lang.Throwable.fillInStackTrace

0.0%3 +0com.mysql.jdbc.SingleByteCharsetConverter.<clinit>

0.0%1 +1java.lang.ClassLoader.findLoadedClass0

0.0%0 +2java.io.FileOutputStream.writeBytes

0.0%0 +2net.sf.hibernate.impl.SessionFactoryImpl.openSession

0.0%0 +2net.sf.hibernate.cfg.Configuration.add

0.0%1 +1net.sf.hibernate.cfg.Binder$CollectionType.<clinit>

0.0%2 +0com.sun.org.apache.xml.internal.utils.XMLChar.<clinit>

0.0%0 +2com.mysql.jdbc.Connection.createNewIO

0.0%0 +1java.lang.ClassLoader.findBootstrapClass

0.0%0 +1java.io.UnixFileSystem.getBooleanAttributes0

0.0%0 +1java.lang.Class.getDeclaredConstructors0

0.0%0 +1java.lang.Class.forName0

0.0%0 +1java.util.zip.ZipFile.getEntry

0.0%1 +0org.objectweb.asm.Label.<init>

0.0%1 +0java.util.zip.ZipEntry.getSize

0.0%1 +0java.nio.HeapCharBuffer.<init>

0.0%1 +0java.lang.ClassLoader.addClass

0.0%1 +0java.lang.AbstractStringBuilder.<init>

0.0%1 +0sun.reflect.UnsafeStaticFieldAccessorImpl.<init>

0.0%0 +1org.objectweb.asm.ClassWriter.visitMethod

0.0%1 +0com.mysql.jdbc.DatabaseMetaData.getIdentifierQuoteString

0.0%0 +1com.mysql.jdbc.Connection.createStatement

99.8%72 + 17098Total interpreted (including elided)

The code statement which is associated with this problem is the creation of the SessionFactory (line 3, below).

> Configuration config = new Configuration();

> config.addClass(User.class);

> SessionFactory sessionFactory = config.buildSessionFactory();

> Session session = sessionFactory.openSession();

Debugs indicate a hangup at the following location.

[java] 704 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0

[java] 705 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - opening new JDBC connection

As you can see, as soon as the connection is attempted, the app hangs. And it hangs at java.net.PlainSocketImpl.initProto.

This seems to point to a jvm problem. If I read this correctly, the initProto() method is hanging for 3 minutes? Is there something I am missing or doing wrong? I have checked jvm.cfg, validated my CLASSPATH, checked and changed my firewall settings, all to no effect. As soon as an application uses a jvm, I pay the up-front cost of a 3 minute startup time.

Any help would be much appreciated.

Thanks,

John Brinnand

[3676 byte] By [john_brinnanda] at [2007-10-1 2:31:54]
# 1

This is the problem, as you noted:

99.2% 0 + 17066 java.net.PlainSocketImpl.initProto

Seems it's timing out. What is it trying to connect to?

Run a simple Helloworld application and see if it tries to connect - I doubt it will.

There is no reason for Java to access a socket unless the application program says to.

ChuckBinga at 2007-7-8 11:39:42 > top of Java-index,Administration Tools,Sun Connection...
# 2
Maybe some network setting problem leading to waiting for a DNS lookup timeout?
BIJ001a at 2007-7-8 11:39:42 > top of Java-index,Administration Tools,Sun Connection...
# 3

This is an old thread, but for what it's worth, I'm seeing the same problem in a completely different application. In linux, it spends 3 minutes in initProto(), then continues happily. In windows, it throws an exception with the message "address already in use." This is very strange, because I'm opening a client socket, so I'm not specifying an address. Does this mean there are no addresses available?

My shot in the dark is that there are so many sockets opening and closing (in the single-digit thousands) that eventually the OS refuses to give it another unprivileged port. Maybe it's a connection-rate-limiting thing?

mhogye5a at 2007-7-8 11:39:42 > top of Java-index,Administration Tools,Sun Connection...
# 4
Process diagnostic tools can tell whether there are too amny sockets open or the like. netstat, the pseudo-flie-system /proc.
BIJ001a at 2007-7-8 11:39:42 > top of Java-index,Administration Tools,Sun Connection...
# 5
We are getting similar behaviour. Sun has a bug open that looks like the problem: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6483406
ross_blacka at 2007-7-8 11:39:42 > top of Java-index,Administration Tools,Sun Connection...