[tcljava-user] JDBC error happens when I call the same script in different processes
Brought to you by:
mdejong
From: Leonardo K. S. <sh...@gm...> - 2016-03-07 17:55:53
|
Hi I am trying to run several processes that connect to a DB, perform some operation and then finishes it. My code looks like this 1. Java calls the script using Process Runtime r = Runtime.getRuntime(); Process p = r.exec(expectPath+" "+expectScriptPath+" "+ticket); SessionLogger sysout = new SessionLogger(logger,p.getInputStream()); sysout.start(); SessionLogger syserr = new SessionLogger(logger,p.getErrorStream()); syserr.start(); try { return p.waitFor(); } catch (InterruptedException e) { log.error(e.getMessage(),e); return -1; } 2. TCL script calls a java method set inputData [ java::call myPackage.TCLDriverWrapper pullNextInputData $ticket ] 3. Java code creates a jdbc connection, performs a simple query and closes the connection private static LegacyDriverTaskInputData pullNextInputData(String token) throws Exception { Connection conn = null; try{ conn = new TCLDriverWrapper().getConnection(); QueryRunner run = new QueryRunner(); ResultSetHandler<LegacyDriverTaskInputData> rsh = new BeanHandler<LegacyDriverTaskInputData>(LegacyDriverTaskInputData.class); LegacyDriverTaskInputData inputData = run.query(conn,"select * from mytable where id = ?",rsh,Long.valueOf(token)); return inputData; } catch (ClassNotFoundException e) { e.printStackTrace(); throw e; } catch (SQLException e) { e.printStackTrace(); throw e; } finally { DbUtils.close(conn); } } where private Connection getConnection() throws Exception{ String driver = "..."; if (driver == null || driver.trim().length()==0) { throw new Exception("..."); } Class.forName(driver); Properties props = new Properties(); props.put("user", MyConfiguration.getProperty("javawrapper.user")); props.put("password", MyConfiguration.getProperty("javawrapper.password")); return DriverManager.getConnection(MyConfiguration.getProperty("javawrapper.jdbc"), props); } One thing I've noticed is that when I trigger just one Process at a time, everything works fine. But if I try to run 3 Processes at the same time (each one in its own thread) I get an error like this Processing java.sql.SQLRecoverableException: IO Error: Connection reset at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:498) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:254) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528) at java.sql.DriverManager.getConnection(DriverManager.java:620) at java.sql.DriverManager.getConnection(DriverManager.java:169) at (...) Caused by: java.net.SocketException: Connection reset at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113) at java.net.SocketOutputStream.write(SocketOutputStream.java:153) at oracle.net.ns.DataPacket.send(DataPacket.java:210) at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:230) at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:321) at oracle.net.ns.NetInputStream.read(NetInputStream.java:268) at oracle.net.ns.NetInputStream.read(NetInputStream.java:190) at oracle.net.ns.NetInputStream.read(NetInputStream.java:107) at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:124) at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:80) at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1137) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:350) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227) at oracle.jdbc.driver.T4CTTIoauthenticate.doOSESSKEY(T4CTTIoauthenticate.java:407) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:416) ... 19 more java.sql.SQLRecoverableException: IO Error: Connection reset at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:498) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:254) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528) at java.sql.DriverManager.getConnection(DriverManager.java:620) at java.sql.DriverManager.getConnection(DriverManager.java:169) (...) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at tcl.lang.reflect.PkgInvoker.invokeMethod(PkgInvoker.java:128) at tcl.lang.JavaInvoke.call(JavaInvoke.java:304) at tcl.lang.JavaInvoke.callStaticMethod(JavaInvoke.java:217) at tcl.lang.JavaCallCmd.cmdProc(JavaCallCmd.java:74) at tcl.lang.AutoloadStub.cmdProc(Extension.java:119) at tcl.lang.Interp.callCommand(Interp.java:1266) Caused by: java.net.SocketException: Connection reset at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113) at java.net.SocketOutputStream.write(SocketOutputStream.java:153) at oracle.net.ns.DataPacket.send(DataPacket.java:210) at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:230) at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:321) at oracle.net.ns.NetInputStream.read(NetInputStream.java:268) at oracle.net.ns.NetInputStream.read(NetInputStream.java:190) at oracle.net.ns.NetInputStream.read(NetInputStream.java:107) at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:124) at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:80) at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1137) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:350) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227) at oracle.jdbc.driver.T4CTTIoauthenticate.doOSESSKEY(T4CTTIoauthenticate.java:407) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:416) ... 19 more java.sql.SQLRecoverableException: IO Error: Connection reset It seems to me that something is not de-allocating some object properly, but I am not sure if it's on the java side, or if it's in the TCL side. Also, I don't know if TCL shares objects for different processes (does not make sense to me). Any clue is welcome. [] Leo |