JDBC 在 Oracle 中的非活动会话

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7569446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:19:59  来源:igfitidea点击:

Inactive session in Oracle by JDBC

oraclejdbc

提问by Ianthe

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.

我们有一个用 Java 编写的 Web 服务,并且正在连接到 Oracle 数据库以进行数据提取。最近,我们在来自我们的 Web 服务 JDBC 的 Oracle 数据库中遇到了太多不活动的会话。

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.

任何人都可以帮助我们吗?为什么它会导致数据库中的会话处于非活动状态,以及解决此问题的方法是什么。

Thank you.

谢谢你。

回答by Justin Cave

What, exactly, is the problem?

究竟是什么问题?

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 STATUSin V$SESSIONis "INACTIVE" at any given point in time. That's perfectly normal.

通常,中间层应用服务器会创建一个连接池。当您的代码请求连接时,它会从池中获取一个已经打开的连接,而不是通过生成新连接到数据库的开销。当您的代码关闭连接时,该连接将返回到池中,而不是通过物理关闭连接的开销。这意味着在任何给定的时间点都会有合理数量的数据库连接,其中STATUSinV$SESSION为“INACTIVE”。这是完全正常的。

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.

即使在负载下,来自中间层的大多数数据库连接在大多数时间都是“非活动的”。“INACTIVE”状态仅表示在您运行查询时,会话没有执行 SQL 语句。大多数连接将大部分时间花在连接池中等待 Java 会话打开它们或等待 Java 会话对数据执行某些操作或等待网络在机器之间传输数据。

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?

您是否真的收到错误消息(即 ORA-00020:超出最大进程数)?或者您只是对 中的条目数量感到困惑V$SESSION