Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
5621ec06
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5621ec06
编写于
7月 04, 2001
作者:
B
Bruce Momjian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove ConnectionHook.java. No longer used, bad code.
上级
0e4d43f4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
95 deletion
+0
-95
src/interfaces/jdbc/org/postgresql/core/ConnectionHook.java
src/interfaces/jdbc/org/postgresql/core/ConnectionHook.java
+0
-95
未找到文件。
src/interfaces/jdbc/org/postgresql/core/ConnectionHook.java
已删除
100644 → 0
浏览文件 @
0e4d43f4
package
org.postgresql.core
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
org.postgresql.Connection
;
/**
* ConnectionHook keeps track of all open Connections. It's used only in
* Java2 (JDK1.3+) VM's, and it's purpose is to close all connections cleanly
* when the VM terminates.
*
* Important: This only works for JDK1.3 or later as it uses methods new to
* that JDK.
*
* This is a singleton object ;-)
*
* How it works: This is an initiated but un-started Thread. When it's created,
* it registers it'self with the Runtime.addShutdownHook() method.
*
* When a Connection is made, two static methods in org.postgresql.Driver are
* called. For pre JDK1.3 these are noops, but for 1.3+ ANT adds calls to
* methods in this class, which add/remove it from an ArrayList.
*
* Now when the VM terminates it starts this thread, which then Itterates
* through the ArrayList and closes each Connection.
*
* Obviously this doesn't trap things like Runtime.halt() or SIGKILL etc, but
* this captures 99% of all other forms of VM termination.
*
*/
public
class
ConnectionHook
implements
Runnable
{
/**
* This ensures that the hook is created and the system is notified of it.
*
* Important: We have to use an instance, as we have to pass a reference to
* the VM.
*/
private
static
final
ConnectionHook
SINGLETON
=
new
ConnectionHook
();
/**
* The currently open connections
*/
private
ArrayList
cons
=
new
ArrayList
();
/**
* Constructor. This is private because we are a singleton. Here we set
* our selves up, and then register with the VM.
*/
private
ConnectionHook
()
{
super
();
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
this
));
}
/**
* Called by Driver, this simply forces us to be created.
*/
public
static
final
void
init
()
{
}
/**
* This is used by org.postgresql.Connection to register itself. Because it's
* called internally, we don't bother with checking to see if it's already
* present (performance boost).
*/
public
static
final
void
open
(
Connection
con
)
{
SINGLETON
.
cons
.
add
(
con
);
}
/**
* This is used by org.postgresql.Connection to remove itself.
*/
public
static
final
void
close
(
Connection
con
)
{
SINGLETON
.
cons
.
remove
(
con
);
}
/**
* This is called by the VM when it terminates. It itterates through the list
* of connections and implicitly closes them.
*/
public
void
run
()
{
Iterator
i
=
cons
.
iterator
();
while
(
i
.
hasNext
())
{
Connection
c
=
(
Connection
)
i
.
next
();
try
{
c
.
close
();
}
catch
(
SQLException
e
)
{
// Ignore as at this point we are dying anyhow ;-)
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录