Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
165492ff
提交
165492ff
authored
11月 29, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
The CompressTool was not multithreading safe.
上级
6857dfdd
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
50 行增加
和
7 行删除
+50
-7
changelog.html
h2/src/docsrc/html/changelog.html
+4
-1
CompressTool.java
h2/src/main/org/h2/tools/CompressTool.java
+6
-5
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+1
-1
TestCompress.java
h2/src/test/org/h2/test/unit/TestCompress.java
+39
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
165492ff
...
...
@@ -18,7 +18,10 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The compression algorithm "LZF" is now about 33% faster than before when compressing small block
<ul><li>
The CompressTool was not multithreading safe. Because of this, the following database
operations where also not multithreading safe (even when using different databases): the SCRIPT command
(only when using compression), the COMPRESS function, and storing CLOB or BLOB data (only when compression is enabled).
</li><li>
The compression algorithm "LZF" is now about 33% faster than before when compressing small block
(around 2 KB). It is much faster than Deflate, but the compression ratio is lower.
</li><li>
Compressing large blocks of data didn't work when using the "Deflate" compression algorithm.
Compressing a lot of data could run out of heap memory.
...
...
h2/src/main/org/h2/tools/CompressTool.java
浏览文件 @
165492ff
...
...
@@ -35,7 +35,6 @@ import org.h2.util.StringUtils;
*/
public
class
CompressTool
{
private
static
final
CompressTool
INSTANCE
=
new
CompressTool
();
private
static
final
int
MAX_BUFFER_SIZE
=
3
*
Constants
.
IO_BUFFER_SIZE_COMPRESS
;
private
byte
[]
cachedBuffer
;
...
...
@@ -54,12 +53,14 @@ public class CompressTool {
}
/**
* Get the singleton.
* Get a new instance. Each instance uses a separate buffer, so multiple
* instances can be used concurrently. However each instance alone is not
* multithreading safe.
*
* @return
the singleton
* @return
a new instance
*/
public
static
CompressTool
getInstance
()
{
return
INSTANCE
;
return
new
CompressTool
()
;
}
/**
...
...
@@ -87,7 +88,7 @@ public class CompressTool {
/**
* INTERNAL
*/
public
synchronized
int
compress
(
byte
[]
in
,
int
len
,
Compressor
compress
,
byte
[]
out
)
{
public
int
compress
(
byte
[]
in
,
int
len
,
Compressor
compress
,
byte
[]
out
)
{
int
newLen
=
0
;
out
[
0
]
=
(
byte
)
compress
.
getAlgorithm
();
int
start
=
1
+
writeInt
(
out
,
1
,
len
);
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
165492ff
...
...
@@ -518,7 +518,7 @@ public abstract class TestBase {
* @param actual the actual value
* @throws AssertionError if the values are not equal
*/
p
rotected
void
assertEquals
(
byte
[]
expected
,
byte
[]
actual
)
{
p
ublic
void
assertEquals
(
byte
[]
expected
,
byte
[]
actual
)
{
assertEquals
(
expected
.
length
,
actual
.
length
);
for
(
int
i
=
0
;
i
<
expected
.
length
;
i
++)
{
if
(
expected
[
i
]
!=
actual
[
i
])
{
...
...
h2/src/test/org/h2/test/unit/TestCompress.java
浏览文件 @
165492ff
...
...
@@ -36,6 +36,7 @@ public class TestCompress extends TestBase {
}
public
void
test
()
throws
Exception
{
testMultiThreaded
();
if
(
testPerformance
)
{
testDatabase
();
}
...
...
@@ -57,6 +58,44 @@ public class TestCompress extends TestBase {
testVariableEnd
();
}
private
void
testMultiThreaded
()
throws
Exception
{
Thread
[]
threads
=
new
Thread
[
3
];
final
boolean
[]
stop
=
new
boolean
[
1
];
final
Exception
[]
ex
=
new
Exception
[
1
];
for
(
int
i
=
0
;
i
<
threads
.
length
;
i
++)
{
Thread
t
=
new
Thread
()
{
public
void
run
()
{
CompressTool
tool
=
CompressTool
.
getInstance
();
byte
[]
buff
=
new
byte
[
1024
];
Random
r
=
new
Random
();
while
(!
stop
[
0
])
{
r
.
nextBytes
(
buff
);
try
{
byte
[]
test
=
tool
.
expand
(
tool
.
compress
(
buff
,
"LZF"
));
assertEquals
(
buff
,
test
);
}
catch
(
Exception
e
)
{
ex
[
0
]
=
e
;
}
}
}
};
threads
[
i
]
=
t
;
t
.
start
();
}
try
{
Thread
.
sleep
(
1000
);
stop
[
0
]
=
true
;
for
(
Thread
t
:
threads
)
{
t
.
join
();
}
}
catch
(
InterruptedException
e
)
{
// ignore
}
if
(
ex
[
0
]
!=
null
)
{
throw
ex
[
0
];
}
}
private
void
testVariableEnd
()
throws
Exception
{
CompressTool
utils
=
CompressTool
.
getInstance
();
StringBuilder
buff
=
new
StringBuilder
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论