提交 f85e917b authored 作者: Thomas Mueller's avatar Thomas Mueller

A new String cache is now created at most once every 5 second, so that out of…

A new String cache is now created at most once every 5 second, so that out of memory exceptions are not artifically delayed.
上级 fe7ae59d
......@@ -21,6 +21,7 @@ import org.h2.message.DbException;
public class StringUtils {
private static SoftReference<String[]> softCache = new SoftReference<String[]>(null);
private static long softCacheCreated;
private static final char[] HEX = "0123456789abcdef".toCharArray();
private StringUtils() {
......@@ -38,13 +39,19 @@ public class StringUtils {
return cache;
}
}
// create a new cache at most every 5 seconds
// so that out of memory exceptions are not delayed
long time = System.currentTimeMillis();
if (softCacheCreated != 0 && time - softCacheCreated < 5000) {
return null;
}
try {
cache = new String[SysProperties.OBJECT_CACHE_SIZE];
} catch (OutOfMemoryError e) {
return null;
softCache = new SoftReference<String[]>(cache);
return cache;
} finally {
softCacheCreated = System.currentTimeMillis();
}
softCache = new SoftReference<String[]>(cache);
return cache;
}
/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论