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