JDBC 在 Oracle 中的非活动会话
我们有一个用 Java 编写的 Web 服务,并且正在连接到 Oracle 数据库以进行数据提取.最近,我们在我们的 Web 服务 JDBC 的 Oracle 数据库中遇到了过多的非活动会话.
We have a web service written in Java and is connecting to Oracle database for data extraction. Recently, we encountered too many inactive session in Oracle database from JDBC which is our web service.
我们非常确定所有连接都在每个进程之后关闭并设置为空.
We are very sure that all the connection is being closed and set to null after every process.
有人可以帮助我们吗?为什么它会导致数据库中的会话处于非活动状态,以及解决此问题的方法是什么.
Can anyone help us in this? Why is it causing inactive session in the database and what can be the solution to this.
谢谢.
推荐答案
问题究竟是什么?
通常,中间层应用服务器会创建一个连接池.当您的代码请求连接时,它会从池中获取一个已经打开的连接,而不是通过生成新连接到数据库的开销.当您的代码关闭连接时,该连接将返回到池中,而不是通过物理关闭连接的开销.这意味着将有合理数量的数据库连接,其中 V$SESSION
中的 STATUS
在任何给定时间点都为INACTIVE".这很正常.
Normally, the middle tier application server creates a connection pool. When your code requests a connection, it gets an already open connection from the pool rather than going through the overhead of spawning a new connection to the database. When your code closes a connection, the connection is returned to the pool rather than going through the overhead of physically closing the connection. That means that there will be a reasonable number of connections to the database where the STATUS
in V$SESSION
is "INACTIVE" at any given point in time. That's perfectly normal.
即使在负载下,来自中间层的大多数数据库连接大部分时间都是非活动"的.INACTIVE"状态仅表示在您运行查询时,会话没有执行 SQL 语句.大多数连接将花费大部分时间在连接池中等待 Java 会话打开它们或等待 Java 会话对数据执行某些操作或等待网络在机器之间传输数据.
Even under load, most database connections from a middle tier are "INACTIVE" most of the time. A status of "INACTIVE" merely means that at the instant you ran the query, the session was not executing a SQL statement. Most connections will spend most of their time either sitting in the connection pool waiting for a Java session to open them or waiting on the Java session to do something with the data or waiting on the network to transfer data between the machines.
您是否真的收到错误消息(即 ORA-00020:超出最大进程数)?或者你只是对 V$SESSION
中的条目数量感到困惑?
Are you actually getting an error (i.e. ORA-00020: maximum number of processes exceeded)? Or are you just confused by the number of entries in V$SESSION
?
相关文章