The connection is closed when using Oracle UCP

2019-04-11 17:18发布

I'm getting random " The connection is closed: The connection is closed" errors when using Oracle UCP, v 12.1.0.2.0. It looks like connection is marked as closed in oracle.ucp.jdbc.proxy.JDBCConnectionProxyFactory#invoke :

if(Clock.isBefore(this.creationTS, this.m_jdbcPooledConnection.getAvailableStartTime()) || Clock.isBefore(this.creationTS, this.m_jdbcPooledConnection.getBorrowedStartTime())) {
      this.m_closed = Boolean.valueOf(true);
}

The Clock.isBefore(this.creationTS, this.m_jdbcPooledConnection.getAvailableStartTime()) returns true.

Could somebody please explain what this check is for?

The getAvailableStartTime is set when connection is retured to the pool, the creationTS - is set when JDBCConnectionProxyFactory is being created and it's being created when giving connection away.

The isBefore looks like this:

public static boolean isBefore(long time1, long time2) {
        return time1 < time2 - 1000L;
}

So, is the condition for the cases when connection was returned less than a second ago?

ps: tried validation query "select 1 from dual" - no effect

标签: oracle jdbc ucp
1条回答
看我几分像从前
2楼-- · 2019-04-11 18:00

If Clock.isBefore(this.creationTS, this.m_jdbcPooledConnection.getAvailableStartTime()) returns true then it means that UCP has recollected the connection and made it available again. This typically happens if you turn on connection harvesting in UCP. UCP detects when a connection is borrowed but not used for too long (poorly designed application) and to avoid connection leaks it will grab the connection back and make it available in the pool. If the original thread then wakes up and attempts to use the connection it gets a connection is closed error.

查看更多
登录 后发表回答