Java-TCL(tclblend)在不同的Java进程中使用时的JDBC连接身份验证错误

时间:2016-03-07 18:00:55

标签: java jdbc tcl

我正在尝试运行多个连接到数据库的进程,执行一些操作然后完成它。

我的代码看起来像这样

Java使用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;
}

TCL脚本调用java方法

set inputData [ java::call myPackage.TCLDriverWrapper pullNextInputData $ticket ]

Java代码创建jdbc连接,执行简单查询并关闭连接

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);
    }
}

,其中

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);
}

我注意到的一件事是,当我一次只触发一个进程时,一切正常。

但是,如果我尝试同时运行3个进程(每个进程都在自己的线程中),我会收到类似的错误

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

在我看来,有些东西没有正确地解除分配对象,但我不确定它是否在java端,或者它是否在TCL端。另外,我不知道TCL是否为不同的进程共享对象(对我来说没有意义)。

欢迎任何线索。

代码在Linux中运行。

0 个答案:

没有答案