diff --git a/src/main/java/net/spy/memcached/ArcusClient.java b/src/main/java/net/spy/memcached/ArcusClient.java index 92ccbc2b5..e863e7267 100644 --- a/src/main/java/net/spy/memcached/ArcusClient.java +++ b/src/main/java/net/spy/memcached/ArcusClient.java @@ -185,7 +185,7 @@ */ public class ArcusClient extends FrontCacheMemcachedClient implements ArcusClientIF { - private static String VERSION = "INIT"; + private static final AtomicReference VERSION = new AtomicReference("INIT"); private static final Logger arcusLogger = LoggerFactory.getLogger(ArcusClient.class); private static final String ARCUS_CLOUD_ADDR = "127.0.0.1:2181"; private static final String DEFAULT_ARCUS_CLIENT_NAME = "ArcusClient"; @@ -4273,37 +4273,31 @@ private void checkDupKey(Collection keyList) { * @return version string */ public static String getVersion() { - if (!VERSION.equals("INIT")) { - return VERSION; + String result = VERSION.get(); + if (!result.equals("INIT")) { + return result; } - synchronized (VERSION) { - if (VERSION.equals("INIT")) { - Enumeration resEnum; - try { - resEnum = Thread.currentThread() - .getContextClassLoader().getResources(JarFile.MANIFEST_NAME); - while (resEnum.hasMoreElements()) { - URL url = resEnum.nextElement(); - InputStream is = url.openStream(); - if (is != null) { - Manifest manifest = new Manifest(is); - java.util.jar.Attributes mainAttribs = manifest.getMainAttributes(); - String version = mainAttribs.getValue("Arcusclient-Version"); - if (version != null) { - VERSION = version; - break; - } - } - } - } catch (Exception e) { - // Failed to get version. - } finally { - if (VERSION.equals("INIT")) { - VERSION = "NONE"; + Enumeration resEnum; + try { + resEnum = Thread.currentThread() + .getContextClassLoader().getResources(JarFile.MANIFEST_NAME); + while (resEnum.hasMoreElements()) { + URL url = resEnum.nextElement(); + InputStream is = url.openStream(); + if (is != null) { + Manifest manifest = new Manifest(is); + java.util.jar.Attributes mainAttribs = manifest.getMainAttributes(); + String version = mainAttribs.getValue("Arcusclient-Version"); + if (version != null) { + VERSION.compareAndSet("INIT", version); + break; } } } + } catch (Exception e) { + // Failed to get version. + VERSION.compareAndSet("INIT", "NONE"); } - return VERSION; + return VERSION.get(); } }