created a ThreadLocal with key of type [oracle.jdbc.driver.AutoKeyInfo$1]

环境:

spring4.3, mybatis3.5.2, ojdbc8_8c(oracle 18c jdbc)

调试状态下退出时,提示:

严重 [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [oracle.jdbc.driver.AutoKeyInfo$1] (value [oracle.jdbc.driver.AutoKeyInfo$1@10289886]) and a value of type [oracle.jdbc.driver.OracleSql] (value [INSERT INTO 某表 (某字段1, 某字段1)
VALUES (?, ?)]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

看提示是个插入语句,此表有主键,为整型,没有使用序列,自己生成的一个数值

警告信息中,AutoKeyInfo来源于:  package oracle.jdbc.driver (class AutoKeyInfo extends OracleResultSetMetaData)

分别在以下三块代码中打上断点,以方便查看是哪里调用的

    private static final ThreadLocal<OracleSql> SQL_PARSER = new ThreadLocal() {
        protected OracleSql initialValue() {
            return new OracleSql((DBConversion)null);
        }
    };

    AutoKeyInfo(String var1) {
        this.sqlKind = SqlKind.UNINITIALIZED;
        this.originalSql = var1;
        this.autoKeyType = 0;
    }

    AutoKeyInfo(String var1, String[] var2) {
        this.sqlKind = SqlKind.UNINITIALIZED;
        this.originalSql = var1;
        this.columnNames = var2;
        this.autoKeyType = 1;
    }

1. 开始调试,定位到调用处(org\mybatis\mybatis\3.5.2\mybatis-3.5.2-sources.jar!\org\apache\ibatis\executor\statement\PreparedStatementHandler.java),

其中: PreparedStatement.RETURN_GENERATED_KEYS 值 固定为 1 ;

 

2. 再进入(oracle\oracle-jdbc\18.3\ojdbc8_18c.jar!\oracle\jdbc\driver\PhysicalConnection.class),在此处生成了 AutoKeyInfo对象

 

 

上网找AutoKeyInfo对象的作用,没有找到合适的说明,猜测是与表自增长字段有关的,但此处不需要自增长,想着在第1步有分支【if (keyColumnNames == null)】

,如果keyColumnNames不为null,走 connection.prepareStatement(sql, keyColumnNames)会不会产生AutoKeyInfo了?

3. 打开mybatis官网(我是访问的中文: https://mybatis.org/mybatis-3/zh/sqlmap-xml.html#insert_update_and_delete)

 找到 insert, update 和 delete部分,看到keyColumn属性,在自己业务层面 dao.xml对应语句的地方,加上: keyColumn = "字段1",再调试

4. 进入到

 

 

 5. 还是走到了第2步,试着在第3步 keyColumn = "字段1" 再加上 useGeneratedKeys="false", 官网上说明 false是默认值,不设置应该就采用false,但想着加上试一下

 

 6. 进入(connection.prepareStatement(sql)):

 

 此次没有再创建 AutoKeyInfo,退出程序,也没有发现警告信息了

 

posted @ 2019-10-14 16:01  唯起  阅读(1136)  评论(0编辑  收藏  举报