Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c080d3a7
提交
c080d3a7
authored
1月 26, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
When restarting a web application in Tomcat, an exception is thrown sometimes.
上级
5f720638
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
40 行增加
和
63 行删除
+40
-63
MemoryUtils.java
h2/src/main/org/h2/util/MemoryUtils.java
+4
-3
StringCache.java
h2/src/main/org/h2/util/StringCache.java
+36
-60
没有找到文件。
h2/src/main/org/h2/util/MemoryUtils.java
浏览文件 @
c080d3a7
...
@@ -81,9 +81,10 @@ public class MemoryUtils {
...
@@ -81,9 +81,10 @@ public class MemoryUtils {
}
}
/**
/**
* Check if the classloader or virtual machine is shut down. In this case
* Check if Tomcat has set the static references to null,
* static references are set to null, which can cause NullPointerExceptions
* which can cause a NullPointerException. A workaround is to
* and can be confusing because it looks like a bug in the application.
* disable the system property org.apache.catalina.loader.
* WebappClassLoader.ENABLE_CLEAR_REFERENCES
*
*
* @return true if static references are set to null
* @return true if static references are set to null
*/
*/
...
...
h2/src/main/org/h2/util/StringCache.java
浏览文件 @
c080d3a7
...
@@ -24,40 +24,6 @@ public class StringCache {
...
@@ -24,40 +24,6 @@ public class StringCache {
// utility class
// utility class
}
}
// testing: cacheHit / miss are public!
// public static int cacheHit = 0, cacheMiss = 0;
// 4703
// public static String get(String s) {
// if (s == null) {
// return s;
// } else if (s.length() == 0) {
// return "";
// }
// if (!Constants.USE_OBJECT_CACHE
// || !ENABLED || s.length() > MAX_CACHE_SIZE / 10) {
// return s;
// }
// int hash = s.hashCode();
// int index = hash & (Constants.OBJECT_CACHE_SIZE - 1);
// String cached = cache[index];
// if (cached != null) {
// if (s.equals(cached)) {
// // cacheHit++;
// return cached;
// }
// }
// // cacheMiss++;
// replace(index, s);
// return s;
// }
// 3500
// public static String get(String s) {
// return s;
// }
// 3906
/**
/**
* Get the string from the cache if possible. If the string has not been
* Get the string from the cache if possible. If the string has not been
* found, it is added to the cache. If there is such a string in the cache,
* found, it is added to the cache. If there is such a string in the cache,
...
@@ -75,25 +41,18 @@ public class StringCache {
...
@@ -75,25 +41,18 @@ public class StringCache {
}
else
if
(
s
.
length
()
==
0
)
{
}
else
if
(
s
.
length
()
==
0
)
{
return
""
;
return
""
;
}
}
String
[]
cache
=
(
String
[])
softCache
.
get
();
int
hash
=
s
.
hashCode
();
int
hash
=
s
.
hashCode
();
if
(
cache
==
null
)
{
String
[]
cache
=
getCache
();
try
{
if
(
cache
!=
null
)
{
cache
=
new
String
[
SysProperties
.
OBJECT_CACHE_SIZE
];
}
catch
(
OutOfMemoryError
e
)
{
return
s
;
}
softCache
=
new
SoftReference
(
cache
);
}
int
index
=
hash
&
(
SysProperties
.
OBJECT_CACHE_SIZE
-
1
);
int
index
=
hash
&
(
SysProperties
.
OBJECT_CACHE_SIZE
-
1
);
String
cached
=
cache
[
index
];
String
cached
=
cache
[
index
];
if
(
cached
!=
null
)
{
if
(
cached
!=
null
)
{
if
(
s
.
equals
(
cached
))
{
if
(
s
.
equals
(
cached
))
{
// cacheHit++;
return
cached
;
return
cached
;
}
}
}
}
cache
[
index
]
=
s
;
cache
[
index
]
=
s
;
}
return
s
;
return
s
;
}
}
...
@@ -115,20 +74,17 @@ public class StringCache {
...
@@ -115,20 +74,17 @@ public class StringCache {
}
else
if
(
s
.
length
()
==
0
)
{
}
else
if
(
s
.
length
()
==
0
)
{
return
""
;
return
""
;
}
}
String
[]
cache
=
(
String
[])
softCache
.
get
();
int
hash
=
s
.
hashCode
();
int
hash
=
s
.
hashCode
();
if
(
cache
==
null
)
{
String
[]
cache
=
getCache
();
cache
=
new
String
[
SysProperties
.
OBJECT_CACHE_SIZE
];
softCache
=
new
SoftReference
(
cache
);
}
int
index
=
hash
&
(
SysProperties
.
OBJECT_CACHE_SIZE
-
1
);
int
index
=
hash
&
(
SysProperties
.
OBJECT_CACHE_SIZE
-
1
);
if
(
cache
!=
null
)
{
String
cached
=
cache
[
index
];
String
cached
=
cache
[
index
];
if
(
cached
!=
null
)
{
if
(
cached
!=
null
)
{
if
(
s
.
equals
(
cached
))
{
if
(
s
.
equals
(
cached
))
{
// cacheHit++;
return
cached
;
return
cached
;
}
}
}
}
}
// create a new object that is not shared
// create a new object that is not shared
// (to avoid out of memory if it is a substring of a big String)
// (to avoid out of memory if it is a substring of a big String)
// NOPMD
// NOPMD
...
@@ -137,6 +93,26 @@ public class StringCache {
...
@@ -137,6 +93,26 @@ public class StringCache {
return
s
;
return
s
;
}
}
private
static
String
[]
getCache
()
{
String
[]
cache
;
// softCache can be null due to a Tomcat problem
// a workaround is disable the system property org.apache.
// catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES
if
(
softCache
!=
null
)
{
cache
=
(
String
[])
softCache
.
get
();
if
(
cache
!=
null
)
{
return
cache
;
}
}
try
{
cache
=
new
String
[
SysProperties
.
OBJECT_CACHE_SIZE
];
}
catch
(
OutOfMemoryError
e
)
{
return
null
;
}
softCache
=
new
SoftReference
(
cache
);
return
cache
;
}
/**
/**
* Clear the cache. This method is used for testing.
* Clear the cache. This method is used for testing.
*/
*/
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论