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

JaQu: the static map Db.TOKENS was not synchronized.

上级 1ea01cfa
......@@ -12,6 +12,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
......@@ -28,8 +29,14 @@ import org.h2.util.JdbcUtils;
//## Java 1.5 begin ##
public class Db {
private static final WeakIdentityHashMap<Object, Token> TOKENS =
Utils.newWeakIdentityHashMap();
/**
* This map It holds unique tokens that are generated by functions such as
* Function.sum(..) in "db.from(p).select(Function.sum(p.unitPrice))". It
* doesn't actually hold column tokens, as those are bound to the query
* itself.
*/
private static final Map<Object, Token> TOKENS =
Collections.synchronizedMap(new WeakIdentityHashMap<Object, Token>());
private final Connection conn;
private final Map<Class<?>, TableDefinition<?>> classMap =
......
......@@ -44,10 +44,6 @@ public class Utils {
return Collections.synchronizedMap(map);
}
public static <A, B> WeakIdentityHashMap<A, B> newWeakIdentityHashMap() {
return new WeakIdentityHashMap<A, B>();
}
public static <A, B> IdentityHashMap<A, B> newIdentityHashMap() {
return new IdentityHashMap<A, B>();
}
......
......@@ -16,13 +16,15 @@ import java.util.Set;
/**
* This hash map uses weak references, so that elements that are no longer
* referenced elsewhere can be garbage collected. It also uses object identity
* to compare keys.
* to compare keys. The garbage collection happens when trying to add new data,
* or when resizing.
*
* @param <K> the keys
* @param <V> the value
*/
//## Java 1.5 begin ##
public class WeakIdentityHashMap<K, V> implements Map<K, V> {
private static final int MAX_LOAD = 90;
private static final WeakReference<Object> DELETED_KEY =
new WeakReference<Object>(null);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论