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