Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
56b9a1a2
提交
56b9a1a2
authored
7月 16, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove dependency from Constants to SysProperties.
上级
0e15d614
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
43 行增加
和
31 行删除
+43
-31
Constants.java
h2/src/main/org/h2/engine/Constants.java
+2
-2
Database.java
h2/src/main/org/h2/engine/Database.java
+5
-2
SysProperties.java
h2/src/main/org/h2/engine/SysProperties.java
+5
-27
Utils.java
h2/src/main/org/h2/util/Utils.java
+31
-0
没有找到文件。
h2/src/main/org/h2/engine/Constants.java
浏览文件 @
56b9a1a2
...
@@ -157,9 +157,9 @@ public class Constants {
...
@@ -157,9 +157,9 @@ public class Constants {
public
static
final
int
CACHE_MIN_RECORDS
=
16
;
public
static
final
int
CACHE_MIN_RECORDS
=
16
;
/**
/**
* The default cache size in KB.
* The default cache size in KB
for each GB of RAM
.
*/
*/
public
static
final
int
CACHE_SIZE_DEFAULT
=
SysProperties
.
scalePropertyForAvailableMemory
(
64
*
1024
)
;
public
static
final
int
CACHE_SIZE_DEFAULT
=
64
*
1024
;
/**
/**
* The default cache type.
* The default cache type.
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
56b9a1a2
...
@@ -206,9 +206,12 @@ public class Database implements DataHandler {
...
@@ -206,9 +206,12 @@ public class Database implements DataHandler {
ci
.
getProperty
(
"ACCESS_MODE_DATA"
,
"rw"
));
ci
.
getProperty
(
"ACCESS_MODE_DATA"
,
"rw"
));
this
.
autoServerMode
=
ci
.
getProperty
(
"AUTO_SERVER"
,
false
);
this
.
autoServerMode
=
ci
.
getProperty
(
"AUTO_SERVER"
,
false
);
this
.
autoServerPort
=
ci
.
getProperty
(
"AUTO_SERVER_PORT"
,
0
);
this
.
autoServerPort
=
ci
.
getProperty
(
"AUTO_SERVER_PORT"
,
0
);
int
defaultCacheSize
=
Utils
.
scaleForAvailableMemory
(
Constants
.
CACHE_SIZE_DEFAULT
);
this
.
cacheSize
=
this
.
cacheSize
=
ci
.
getProperty
(
"CACHE_SIZE"
,
Constants
.
CACHE_SIZE_DEFAULT
);
ci
.
getProperty
(
"CACHE_SIZE"
,
defaultCacheSize
);
this
.
pageSize
=
ci
.
getProperty
(
"PAGE_SIZE"
,
Constants
.
DEFAULT_PAGE_SIZE
);
this
.
pageSize
=
ci
.
getProperty
(
"PAGE_SIZE"
,
Constants
.
DEFAULT_PAGE_SIZE
);
if
(
"r"
.
equals
(
accessModeData
))
{
if
(
"r"
.
equals
(
accessModeData
))
{
readOnly
=
true
;
readOnly
=
true
;
}
}
...
...
h2/src/main/org/h2/engine/SysProperties.java
浏览文件 @
56b9a1a2
...
@@ -5,10 +5,6 @@
...
@@ -5,10 +5,6 @@
*/
*/
package
org
.
h2
.
engine
;
package
org
.
h2
.
engine
;
import
java.lang.management.ManagementFactory
;
import
java.lang.management.OperatingSystemMXBean
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.Utils
;
import
org.h2.util.Utils
;
...
@@ -460,6 +456,10 @@ public class SysProperties {
...
@@ -460,6 +456,10 @@ public class SysProperties {
*/
*/
public
static
final
boolean
USE_THREAD_CONTEXT_CLASS_LOADER
=
public
static
final
boolean
USE_THREAD_CONTEXT_CLASS_LOADER
=
Utils
.
getProperty
(
"h2.useThreadContextClassLoader"
,
false
);
Utils
.
getProperty
(
"h2.useThreadContextClassLoader"
,
false
);
static
{
System
.
out
.
println
(
"init sysprop"
);
}
/**
/**
* System property <code>h2.serializeJavaObject</code>
* System property <code>h2.serializeJavaObject</code>
...
@@ -552,29 +552,7 @@ public class SysProperties {
...
@@ -552,29 +552,7 @@ public class SysProperties {
// ignore
// ignore
}
}
}
}
return
scaleProperty
ForAvailableMemory
(
defaultValue
);
return
Utils
.
scale
ForAvailableMemory
(
defaultValue
);
}
}
public
static
int
scalePropertyForAvailableMemory
(
int
defaultValue
)
{
long
maxMemory
=
Runtime
.
getRuntime
().
maxMemory
();
if
(
maxMemory
!=
Long
.
MAX_VALUE
)
{
// we are limited by an -XmX parameter
return
(
int
)
(
defaultValue
*
maxMemory
/
(
1024
*
1024
*
1024
));
}
try
{
OperatingSystemMXBean
mxBean
=
ManagementFactory
.
getOperatingSystemMXBean
();
// this method is only available on the class com.sun.management.OperatingSystemMXBean, which mxBean
// is an instance of under the Oracle JDK, but it is not present on Android and other JDK's
Method
method
=
Class
.
forName
(
"com.sun.management.OperatingSystemMXBean"
).
getMethod
(
"getTotalPhysicalMemorySize"
);
long
physicalMemorySize
=
((
Number
)
method
.
invoke
(
mxBean
)).
longValue
();
return
(
int
)
(
defaultValue
*
physicalMemorySize
/
(
1024
*
1024
*
1024
));
}
catch
(
Exception
e
)
{
// ignore
}
return
defaultValue
;
}
}
}
h2/src/main/org/h2/util/Utils.java
浏览文件 @
56b9a1a2
...
@@ -8,6 +8,8 @@ package org.h2.util;
...
@@ -8,6 +8,8 @@ package org.h2.util;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.lang.management.ManagementFactory
;
import
java.lang.management.OperatingSystemMXBean
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Modifier
;
import
java.lang.reflect.Modifier
;
...
@@ -734,6 +736,35 @@ public class Utils {
...
@@ -734,6 +736,35 @@ public class Utils {
}
}
return
defaultValue
;
return
defaultValue
;
}
}
/**
* Scale the value with the available memory. If 1 GB of RAM is available,
* the value is returned, if 2 GB are available, then twice the value, and so on.
*
* @param value the value to scale
* @return the scaled value
*/
public
static
int
scaleForAvailableMemory
(
int
value
)
{
long
maxMemory
=
Runtime
.
getRuntime
().
maxMemory
();
if
(
maxMemory
!=
Long
.
MAX_VALUE
)
{
// we are limited by an -XmX parameter
return
(
int
)
(
value
*
maxMemory
/
(
1024
*
1024
*
1024
));
}
try
{
OperatingSystemMXBean
mxBean
=
ManagementFactory
.
getOperatingSystemMXBean
();
// this method is only available on the class com.sun.management.OperatingSystemMXBean, which mxBean
// is an instance of under the Oracle JDK, but it is not present on Android and other JDK's
Method
method
=
Class
.
forName
(
"com.sun.management.OperatingSystemMXBean"
).
getMethod
(
"getTotalPhysicalMemorySize"
);
long
physicalMemorySize
=
((
Number
)
method
.
invoke
(
mxBean
)).
longValue
();
return
(
int
)
(
value
*
physicalMemorySize
/
(
1024
*
1024
*
1024
));
}
catch
(
Exception
e
)
{
// ignore
}
return
value
;
}
/**
/**
* The utility methods will try to use the provided class factories to
* The utility methods will try to use the provided class factories to
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论