1

We have several servers that each run an Oracle database 11g Release 11.2.0.1.0 - 64bit. We are connecting via JDBC like this:

public Connection createConnection(String drvClass, String connURL, String user, String pass)
        throws ClassNotFoundException, SQLException {
    Class.forName(drvClass);
    Connection conn = DriverManager.getConnection(connURL, user, pass);
    for (SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning()) {
        System.out.println("SQL Warning:");
        System.out.println("State  : " + warn.getSQLState());
        System.out.println("Message: " + warn.getMessage());
        System.out.println("Error  : " + warn.getErrorCode());
    }
    return conn;
}

drvClass would be oracle.jdbc.OracleDriver. The program which tries to connect runs on each server. The database is reachable from out of other programs with the exact same connection properties.

It is also possible to let this program run on another server and let it connect to the problematic database. It can establish the connection. The program does not work if it's running on the server locally. We tried both IP and servername.

On one server the code hangs at DriverManager.getConnection() an I cannot find out why. Does anyone have any idea what could cause this?

There is no entry about this in the DB logs.

Stacktrace of blocking thread:

"pool-27-thread-1" - Thread t@1483
   java.lang.Thread.State: RUNNABLE
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at oracle.net.ns.Packet.receive(Packet.java:239)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:255)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:973)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:291)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:490)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:202)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:474)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.companyname.DBConnectionInternal.DBConnection.createConnection(DBConnection.java:19)
at com.companyname.exportadapter.ExportCollector.initDatabase(ExportCollector.java:259)
at com.companyname.exportadapter.ExportCollector.run(ExportCollector.java:120)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Locked ownable synchronizers:
- locked <50be77> (a java.util.concurrent.ThreadPoolExecutor$Worker)

If i set DriverManager.setLoginTimeout(10) then i get Io exception: Socket read timed out.

Moh-Aw
  • 2,976
  • 2
  • 30
  • 44
  • How many clients are trying concurrently to access the database? Maybe you did hit any server limitation (maximum open connections for example)? – Jorge_B May 26 '14 at 10:51
  • the database currently has around 80 connections. `SELECT value FROM v$parameter WHERE name = 'sessions'` returns 772 possible connections. – Moh-Aw May 26 '14 at 10:54
  • What is the Stacktrace for the blocking Thread? recv,sendv may point you to the problem. – Grim May 26 '14 at 10:54
  • i added a stacktrace of the blocking thread but i can't find anything – Moh-Aw May 26 '14 at 11:57
  • It is possible to run this application from a different server. It can connect to the problematic server with no problems. But as soon as the software runs on this server the connection hangs. – Moh-Aw May 26 '14 at 12:19
  • if I set the login timeout to 10 seconds i get: Io exception: Socket read timed out. – Moh-Aw May 26 '14 at 13:00

3 Answers3

1

you may making some unneccessary connections.

make Connection class static ,whenever you are creating new connection check older is alive or close then and then you must create new connection other wise return old connection.

like

 if(conn!=null & !conn.isClosed()){ 
// code for create connection
}

It also depends on how the database side is configured, so check it with DBA of your system.

I would like to suggest using Connection pooling.

hope this helps.

Sanjay Rabari
  • 2,091
  • 1
  • 17
  • 32
  • I think we still don't know that. Maybe the client is managing well the connections, and it closes every connection it opens. I rather think that the problem may be in many clients opening concurrently connections against the database and reaching a server limit - something that could be solved by putting some connection pool in the middle – Jorge_B May 26 '14 at 10:55
  • there is no open connection with this user at the time the problem occurs. The connection gets closed in a finally block (if it would have been opened) in the invoking class. – Moh-Aw May 26 '14 at 11:18
  • 2
    Creating static connections is a bad idea, it will actually lead to connection leaks than prevent them. I'd suggest to use try-with-resources combined with a datasource that provides connection pooling. – Mark Rotteveel May 26 '14 at 12:19
0

You might want to enable JDBC debug logging for the ojdbc driver: http://docs.oracle.com/cd/B28359_01/java.111/b31224/diagnose.htm That might give you some information about what the driver is doing.

Have you tried telnet-ing to the database server from the client machine (to assert it's reachable)?

Rein
  • 478
  • 3
  • 3
0

The server was misconfigured. For some reason it had a virtual adapter configured which returned an ip to which nothing could connect. From outside the resolving worked correctly. Don't know why it never timed out with the wrong IP though.

Moh-Aw
  • 2,976
  • 2
  • 30
  • 44