--- loci/common/Location.java.orig 2011-01-28 02:48:36.000000000 +0100 +++ loci/common/Location.java 2011-01-28 03:36:55.000000000 +0100 @@ -55,7 +55,12 @@ // -- Static fields -- /** Map from given filenames to actual filenames. */ - private static HashMap idMap = new HashMap(); + private static ThreadLocal> + idMap = new ThreadLocal>() { + protected HashMap initialValue() { + return new HashMap(); + } + }; // -- Fields -- @@ -105,16 +110,16 @@ */ public static void mapId(String id, String filename) { if (id == null) return; - if (filename == null) idMap.remove(id); - else idMap.put(id, filename); + if (filename == null) getIdMap().remove(id); + else getIdMap().put(id, filename); LOGGER.debug("Location.mapId: {} -> {}", id, filename); } /** Maps the given id to the given IRandomAccess object. */ public static void mapFile(String id, IRandomAccess ira) { if (id == null) return; - if (ira == null) idMap.remove(id); - else idMap.put(id, ira); + if (ira == null) getIdMap().remove(id); + else getIdMap().put(id, ira); LOGGER.debug("Location.mapFile: {} -> {}", id, ira); } @@ -128,26 +133,26 @@ * @see #mapId(String, String) */ public static String getMappedId(String id) { - if (idMap == null) return id; + if (getIdMap() == null) return id; String filename = null; - if (id != null && (idMap.get(id) instanceof String)) { - filename = (String) idMap.get(id); + if (id != null && (getIdMap().get(id) instanceof String)) { + filename = (String) getIdMap().get(id); } return filename == null ? id : filename; } /** Gets the random access handle for the given id. */ public static IRandomAccess getMappedFile(String id) { - if (idMap == null) return null; + if (getIdMap() == null) return null; IRandomAccess ira = null; - if (id != null && (idMap.get(id) instanceof IRandomAccess)) { - ira = (IRandomAccess) idMap.get(id); + if (id != null && (getIdMap().get(id) instanceof IRandomAccess)) { + ira = (IRandomAccess) getIdMap().get(id); } return ira; } /** Return the id mapping. */ - public static HashMap getIdMap() { return idMap; } + public static HashMap getIdMap() { return idMap.get(); } /** * Set the id mapping using the given HashMap. @@ -156,7 +161,7 @@ */ public static void setIdMap(HashMap map) { if (map == null) throw new IllegalArgumentException("map cannot be null"); - idMap = map; + idMap.set(map); } /**