简体   繁体   English

在JBOSS 7.2中释放包装的连接

[英]Freeing Wrapped connection in JBOSS 7.2

We are migrating our app servers from Weblogic to JBoss, we are facing a an issue with Datasource managed by Jboss which is not closing the Ironjacamar wrapped connection. 我们正在将应用程序服务器从Weblogic迁移到JBoss,而Jboss管理的数据源面临一个问题,该问题并未关闭Ironjacamar包装的连接。

Environament : Jboss 7.2 , Ironjacamar 1.0.15 ,Oracle 11G 环境:Jboss 7.2,Ironjacamar 1.0.15,Oracle 11G

While getting connection from the Oracle datasource we wrapping the connection to Oracle Connection using the appserver(Weblogic/Jboss) specific wrapper like below.If we don't wrap this we wont be able to use oracle features like ArrayDescriptors.We should change our applications such way that they work in both weblogic and jboss. 从Oracle数据源获取连接时,我们使用如下特定于appserver(Weblogic / Jboss)的专用包装器将连接包装到Oracle Connection,如果不包装,我们将无法使用ArrayDescriptors之类的Oracle功能,应更改应用程序这样它们就可以在weblogic和jboss中工作。

Connectionutil.java: Connectionutil.java:

public static Connection getConnection(String jndiName) throws NamingException, SQLException {
    InitialContext initContext = new InitialContext();
    Context envContext = (Context) initContext.lookup("java:/comp/env");
    DataSource dataSource = (DataSource) envContext.lookup(jndiName);
    Connection connection = dataSource.getConnection();
    connection= unwrapConnection(connection);
    return connection;
}



private static Connection  unwrapConnection(Connection connection) throws SQLException {
    if(isWeblogic) {
        if(connection instanceof weblogic.jdbc.extensions.WLConnection) {
            System.out.println("Datasource is maintained by Weblogc so Unwarping Weblogic JDBC Connection to oracle.jdbc.OracleConnection. Driver name is " + connection.getMetaData().getDriverName());
            return (oracle.jdbc.OracleConnection) ((weblogic.jdbc.extensions.WLConnection) connection).getVendorConnection();
        }
    } else if(isJboss) {
        if(connection instanceof org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6) {
            System.out.println("Datasource is maintained by Jboss so Unwarping Jboss JDBC Connection to oracle.jdbc.OracleConnection. Driver name is " + connection.getMetaData().getDriverName());
            return (oracle.jdbc.OracleConnection) ((org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6) connection).getUnderlyingConnection();
        }
    }

    // log.debug("{called getConnection(non weblogic type) - " + connection.getMetaData().getDriverName() + "}");
    return connection;
}

Whenever a connection is required we will call Datasource like below : 每当需要连接时,我们将如下所示调用数据源:

//some code 
connection = Connectionutil.getConnection("jdbc/SomeDS");


finally()
{
connection.close();//closing the connection
}

Problem here is even after closing the connection from client the connection is not freed by jboss pool if a new connection is requested , pool is giving other available connection untill the pool exhausts(maxCOnnections) with out reusing the closed connections. 这里的问题是,即使从客户端关闭了连接之后,如果请求了新的连接,jboss池也不会释放该连接,池会提供其他可用的连接,直到该池耗尽(maxCOnnections)而没有重新使用关闭的连接。 I expected that jboss connection pool manager would take care of managing connection it did not happened. 我希望jboss连接池管理器可以管理未发生的连接。

I found a solution to a problem similar to above in Jboss Community : https://community.jboss.org/thread/72958?start=0&tstart=0 and we able to resolved the issue for standalone applications like below. 我在Jboss社区中找到了与上述问题类似的解决方案: https ://community.jboss.org/thread/72958?start =0& tstart =0 ,我们能够为以下独立应用程序解决此问题。

   Connection logicalConnection= dataSource.getConnection();//got the connection from DS

Connection oracleConnection= Connectionutil.unwrapConnection(connection );//unwrapping and wrappig to oracle connection

//some code 

    {
    finally()
    {
    logicalConnection.close;// here closing logical connection instead of oracle connection. Then jboss is reusing the connections.
    }

But in case of J2EE application which use frameworks like spring who manages connection opening and closing , i did not understand how to get container wrapped connection instead of oracle connection like above in such cases? 但是在使用像spring这样管理连接打开和关闭的框架的J2EE应用程序的情况下,在这种情况下,我不明白如何获取容器包装的连接而不是上面的oracle连接?

Can anyone suggest me better way to solve the above issue?? 谁能建议我解决上述问题的更好方法?

spring gives wrapper connection but at our end we needed it to wrap to oracle connection for many Array descriptor operation so we implemented a javax.sql.DataSource getConnection method and configured spring to get this connection using org.springframework.jndi.JndiObjectFactoryBean so spring is closing oracle connection which ,i think , is causing the issue. spring提供了包装器连接,但在最后,我们需要将其包装到oracle连接以进行许多Array描述符操作,因此我们实现了javax.sql.DataSource getConnection方法并配置了spring以使用org.springframework.jndi.JndiObjectFactoryBean获得此连接,因此spring是我认为关闭oracle连接是导致此问题的原因。

Indeed, that is causing the issue. 确实,这就是问题所在。 Don't do this. 不要这样

Instead, let Spring and other frameworks get the wrapped connection. 相反,让Spring和其他框架获取包装的连接。 Only unwrap the connection when you need array descriptors in your app, in the code, otherwise let everything use the wrapped connections provided by the container. 仅在代码中需要在应用程序中使用数组描述符时才打开连接的包装,否则让所有内容都使用容器提供的包装的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM