From c2ab09096483a9edaee4a504137487bfe0cbadf2 Mon Sep 17 00:00:00 2001 From: Jason CHAN Date: Tue, 25 Nov 2014 11:09:56 +0800 Subject: [PATCH] add synchronized to protect the map, to fix the bug: java.util.ConcurrentModificationException at java.util.IdentityHashMap.remove(IdentityHashMap.java:729) at com.ycache.danga.MemCached.SockIOPool.clearHostFromPool(Unknown Source) at com.ycache.danga.MemCached.SockIOPool.createSocket(Unknown Source) at com.ycache.danga.MemCached.SockIOPool.getConnection(Unknown Source) at com.ycache.danga.MemCached.SockIOPool.getSock(Unknown Source) at com.ycache.danga.MemCached.MemCachedClient.get(Unknown Source) at com.ycache.danga.MemCached.MemCachedClient.get(Unknown Source) at com.yihaodian.common.ycache.memcache.impl.BaseMemcacheProxy.get(Unknown Source) --- .gitignore | 1 + src/com/meetup/memcached/SockIOPool.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8982d11..a0f95f2 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ dist/ scratch/ .cachedir/ memcached-release* +/bin diff --git a/src/com/meetup/memcached/SockIOPool.java b/src/com/meetup/memcached/SockIOPool.java index 6fe0c92..5377995 100644 --- a/src/com/meetup/memcached/SockIOPool.java +++ b/src/com/meetup/memcached/SockIOPool.java @@ -1066,7 +1066,7 @@ public SockIO getConnection( String host ) { * @param host host this socket is connected to * @param socket socket to add */ - protected void addSocketToPool( Map> pool, String host, SockIO socket ) { + synchronized protected void addSocketToPool( Map> pool, String host, SockIO socket ) { if ( pool.containsKey( host ) ) { Map sockets = pool.get( host ); @@ -1111,7 +1111,7 @@ protected void removeSocketFromPool( Map> pool, String h * @param pool pool to clear * @param host host to clear */ - protected void clearHostFromPool( Map> pool, String host ) { + synchronized protected void clearHostFromPool( Map> pool, String host ) { if ( pool.containsKey( host ) ) { Map sockets = pool.get( host );