提交 8ad8fe0a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use ConcurrentHashMap instead of Collections.synchronizedMap(new HashMap<>())

上级 205f89dd
......@@ -10,11 +10,12 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.h2.util.SoftHashMap;
/**
......@@ -45,8 +46,7 @@ final class FullTextSettings {
/**
* The set of indexes in this database.
*/
private final Map<Integer, IndexInfo> indexes = Collections
.synchronizedMap(new HashMap<Integer, IndexInfo>());
private final ConcurrentHashMap<Integer, IndexInfo> indexes = new ConcurrentHashMap<>();
/**
* The prepared statement cache.
......
......@@ -21,6 +21,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.h2.Driver;
import org.h2.api.ErrorCode;
import org.h2.engine.Constants;
......@@ -49,8 +51,7 @@ public class TcpServer implements Service {
*/
private static final String MANAGEMENT_DB_PREFIX = "management_db_";
private static final Map<Integer, TcpServer> SERVERS =
Collections.synchronizedMap(new HashMap<Integer, TcpServer>());
private static final ConcurrentHashMap<Integer, TcpServer> SERVERS = new ConcurrentHashMap<>();
private int port;
private boolean portIsSet;
......
......@@ -9,10 +9,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.FileChannel;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.h2.util.MathUtils;
/**
......@@ -25,7 +23,7 @@ public abstract class FilePath {
private static FilePath defaultProvider;
private static Map<String, FilePath> providers;
private static ConcurrentHashMap<String, FilePath> providers;
/**
* The prefix for temporary files.
......@@ -66,8 +64,7 @@ public abstract class FilePath {
private static void registerDefaultProviders() {
if (providers == null || defaultProvider == null) {
Map<String, FilePath> map = Collections.synchronizedMap(
new HashMap<String, FilePath>());
ConcurrentHashMap<String, FilePath> map = new ConcurrentHashMap<>();
for (String c : new String[] {
"org.h2.store.fs.FilePathDisk",
"org.h2.store.fs.FilePathMem",
......
......@@ -5,10 +5,7 @@
*/
package org.h2.util;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
/**
......@@ -17,10 +14,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class SynchronizedVerifier {
private static volatile boolean enabled;
private static final Map<Class<?>, AtomicBoolean> DETECT =
Collections.synchronizedMap(new HashMap<Class<?>, AtomicBoolean>());
private static final Map<Object, Object> CURRENT =
Collections.synchronizedMap(new IdentityHashMap<>());
private static final ConcurrentHashMap<Class<?>, AtomicBoolean> DETECT = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<Object, Object> CURRENT = new ConcurrentHashMap<>();
/**
* Enable or disable detection for a given class.
......
......@@ -10,9 +10,7 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* This sample application shows how to cache prepared statements.
......@@ -21,9 +19,7 @@ public class CachedPreparedStatements {
private Connection conn;
private Statement stat;
private final Map<String, PreparedStatement> prepared =
Collections.synchronizedMap(
new HashMap<String, PreparedStatement>());
private final ConcurrentHashMap<String, PreparedStatement> prepared = new ConcurrentHashMap<>();
/**
* This method is called when executing this sample application from the
......
......@@ -10,9 +10,8 @@ import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.h2.api.Trigger;
/**
......@@ -21,8 +20,7 @@ import org.h2.api.Trigger;
*/
public class TriggerPassData implements Trigger {
private static final Map<String, TriggerPassData> TRIGGERS =
Collections.synchronizedMap(new HashMap<String, TriggerPassData>());
private static final ConcurrentHashMap<String, TriggerPassData> TRIGGERS = new ConcurrentHashMap<>();
private String triggerData;
/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论