Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b87d4a71
提交
b87d4a71
authored
7 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split DatabaseCloser into DelayedDatabaseCloser and OnExitDatabaseCloser
上级
04564b6e
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
85 行增加
和
33 行删除
+85
-33
Database.java
h2/src/main/org/h2/engine/Database.java
+4
-15
DelayedDatabaseCloser.java
h2/src/main/org/h2/engine/DelayedDatabaseCloser.java
+17
-18
OnExitDatabaseCloser.java
h2/src/main/org/h2/engine/OnExitDatabaseCloser.java
+64
-0
没有找到文件。
h2/src/main/org/h2/engine/Database.java
浏览文件 @
b87d4a71
...
@@ -157,7 +157,7 @@ public class Database implements DataHandler {
...
@@ -157,7 +157,7 @@ public class Database implements DataHandler {
private
int
powerOffCount
=
initialPowerOffCount
;
private
int
powerOffCount
=
initialPowerOffCount
;
private
int
closeDelay
;
private
int
closeDelay
;
private
DatabaseCloser
delayedCloser
;
private
D
elayedD
atabaseCloser
delayedCloser
;
private
volatile
boolean
closing
;
private
volatile
boolean
closing
;
private
boolean
ignoreCase
;
private
boolean
ignoreCase
;
private
boolean
deleteFilesOnDisconnect
;
private
boolean
deleteFilesOnDisconnect
;
...
@@ -168,7 +168,7 @@ public class Database implements DataHandler {
...
@@ -168,7 +168,7 @@ public class Database implements DataHandler {
private
boolean
referentialIntegrity
=
true
;
private
boolean
referentialIntegrity
=
true
;
/** ie. the MVCC setting */
/** ie. the MVCC setting */
private
boolean
multiVersion
;
private
boolean
multiVersion
;
private
DatabaseCloser
closeOnExit
;
private
OnExit
DatabaseCloser
closeOnExit
;
private
Mode
mode
=
Mode
.
getRegular
();
private
Mode
mode
=
Mode
.
getRegular
();
private
boolean
multiThreaded
;
private
boolean
multiThreaded
;
private
int
maxOperationMemory
=
private
int
maxOperationMemory
=
...
@@ -290,8 +290,7 @@ public class Database implements DataHandler {
...
@@ -290,8 +290,7 @@ public class Database implements DataHandler {
open
(
traceLevelFile
,
traceLevelSystemOut
,
ci
);
open
(
traceLevelFile
,
traceLevelSystemOut
,
ci
);
if
(
closeAtVmShutdown
)
{
if
(
closeAtVmShutdown
)
{
try
{
try
{
closeOnExit
=
new
DatabaseCloser
(
this
,
0
,
true
);
closeOnExit
=
new
OnExitDatabaseCloser
(
this
);
Runtime
.
getRuntime
().
addShutdownHook
(
closeOnExit
);
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
// shutdown in progress - just don't register the handler
// shutdown in progress - just don't register the handler
// (maybe an application wants to write something into a
// (maybe an application wants to write something into a
...
@@ -1240,10 +1239,7 @@ public class Database implements DataHandler {
...
@@ -1240,10 +1239,7 @@ public class Database implements DataHandler {
}
else
if
(
closeDelay
<
0
)
{
}
else
if
(
closeDelay
<
0
)
{
return
;
return
;
}
else
{
}
else
{
delayedCloser
=
new
DatabaseCloser
(
this
,
closeDelay
*
1000
,
false
);
delayedCloser
=
new
DelayedDatabaseCloser
(
this
,
closeDelay
*
1000
);
delayedCloser
.
setName
(
"H2 Close Delay "
+
getShortName
());
delayedCloser
.
setDaemon
(
true
);
delayedCloser
.
start
();
}
}
}
}
if
(
session
!=
systemSession
&&
if
(
session
!=
systemSession
&&
...
@@ -1363,13 +1359,6 @@ public class Database implements DataHandler {
...
@@ -1363,13 +1359,6 @@ public class Database implements DataHandler {
traceSystem
.
close
();
traceSystem
.
close
();
if
(
closeOnExit
!=
null
)
{
if
(
closeOnExit
!=
null
)
{
closeOnExit
.
reset
();
closeOnExit
.
reset
();
try
{
Runtime
.
getRuntime
().
removeShutdownHook
(
closeOnExit
);
}
catch
(
IllegalStateException
e
)
{
// ignore
}
catch
(
SecurityException
e
)
{
// applets may not do that - ignore
}
closeOnExit
=
null
;
closeOnExit
=
null
;
}
}
if
(
deleteFilesOnDisconnect
&&
persistent
)
{
if
(
deleteFilesOnDisconnect
&&
persistent
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/DatabaseCloser.java
→
h2/src/main/org/h2/engine/D
elayedD
atabaseCloser.java
浏览文件 @
b87d4a71
...
@@ -10,27 +10,28 @@ import java.lang.ref.WeakReference;
...
@@ -10,27 +10,28 @@ import java.lang.ref.WeakReference;
import
org.h2.message.Trace
;
import
org.h2.message.Trace
;
/**
/**
* This class is responsible to close a database
if the application did not
* This class is responsible to close a database
after the specified delay. A
*
close a connection. A database closer object only exists if there is no user
*
database closer object only exists if there is no user connected to the
*
connected to the
database.
* database.
*/
*/
class
DatabaseCloser
extends
Thread
{
class
D
elayedD
atabaseCloser
extends
Thread
{
private
final
boolean
shutdownHook
;
private
final
Trace
trace
;
private
final
Trace
trace
;
private
volatile
WeakReference
<
Database
>
databaseRef
;
private
volatile
WeakReference
<
Database
>
databaseRef
;
private
int
delayInMillis
;
private
int
delayInMillis
;
D
atabaseCloser
(
Database
db
,
int
delayInMillis
,
boolean
shutdownHook
)
{
D
elayedDatabaseCloser
(
Database
db
,
int
delayInMillis
)
{
this
.
databaseRef
=
new
WeakReference
<>(
db
);
databaseRef
=
new
WeakReference
<>(
db
);
this
.
delayInMillis
=
delayInMillis
;
this
.
delayInMillis
=
delayInMillis
;
this
.
shutdownHook
=
shutdownHook
;
trace
=
db
.
getTrace
(
Trace
.
DATABASE
);
trace
=
db
.
getTrace
(
Trace
.
DATABASE
);
setName
(
"H2 Close Delay "
+
db
.
getShortName
());
setDaemon
(
true
);
start
();
}
}
/**
/**
* Stop and disable the database closer. This method is called after
the
* Stop and disable the database closer. This method is called after
a session
*
database has been closed, or after a session
has been created.
* has been created.
*/
*/
void
reset
()
{
void
reset
()
{
databaseRef
=
null
;
databaseRef
=
null
;
...
@@ -46,18 +47,16 @@ class DatabaseCloser extends Thread {
...
@@ -46,18 +47,16 @@ class DatabaseCloser extends Thread {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// ignore InterruptedException
// ignore InterruptedException
}
}
if
(
databaseRef
==
null
)
{
WeakReference
<
Database
>
ref
=
databaseRef
;
if
(
ref
==
null
||
ref
.
get
()
==
null
)
{
return
;
return
;
}
}
}
}
Database
database
=
null
;
Database
database
;
WeakReference
<
Database
>
ref
=
this
.
databaseRef
;
WeakReference
<
Database
>
ref
=
databaseRef
;
if
(
ref
!=
null
)
{
if
(
ref
!=
null
&&
(
database
=
ref
.
get
())
!=
null
)
{
database
=
ref
.
get
();
}
if
(
database
!=
null
)
{
try
{
try
{
database
.
close
(
shutdownHook
);
database
.
close
(
false
);
}
catch
(
RuntimeException
e
)
{
}
catch
(
RuntimeException
e
)
{
// this can happen when stopping a web application,
// this can happen when stopping a web application,
// if loading classes is no longer allowed
// if loading classes is no longer allowed
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/OnExitDatabaseCloser.java
0 → 100644
浏览文件 @
b87d4a71
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
engine
;
import
java.lang.ref.WeakReference
;
import
org.h2.message.Trace
;
/**
* This class is responsible to close a database on JVM shutdown.
*/
class
OnExitDatabaseCloser
extends
Thread
{
private
final
Trace
trace
;
private
volatile
WeakReference
<
Database
>
databaseRef
;
OnExitDatabaseCloser
(
Database
db
)
{
databaseRef
=
new
WeakReference
<>(
db
);
trace
=
db
.
getTrace
(
Trace
.
DATABASE
);
Runtime
.
getRuntime
().
addShutdownHook
(
this
);
}
/**
* Stop and disable the database closer. This method is called after the
* database has been closed.
*/
void
reset
()
{
databaseRef
=
null
;
try
{
Runtime
.
getRuntime
().
removeShutdownHook
(
this
);
}
catch
(
IllegalStateException
e
)
{
// ignore
}
catch
(
SecurityException
e
)
{
// applets may not do that - ignore
}
}
@Override
public
void
run
()
{
Database
database
;
WeakReference
<
Database
>
ref
=
databaseRef
;
if
(
ref
!=
null
&&
(
database
=
ref
.
get
())
!=
null
)
{
try
{
database
.
close
(
true
);
}
catch
(
RuntimeException
e
)
{
// this can happen when stopping a web application,
// if loading classes is no longer allowed
// it would throw an IllegalStateException
try
{
trace
.
error
(
e
,
"could not close the database"
);
// if this was successful, we ignore the exception
// otherwise not
}
catch
(
Throwable
e2
)
{
e
.
addSuppressed
(
e2
);
throw
e
;
}
}
}
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论