@Override protected Map<Stack<?>, WeakOrderQueue> initialValue() { return new WeakHashMap<Stack<?>, WeakOrderQueue>(); } };
@Override protected Map<Class<?>, String> initialValue() { return new WeakHashMap<Class<?>, String>(); } };
public Map<Class<?>, Boolean> handlerSharableCache() { Map<Class<?>, Boolean> cache = handlerSharableCache; if (cache == null) { // Start with small capacity to keep memory overhead as low as possible. handlerSharableCache = cache = new WeakHashMap<Class<?>, Boolean>(4); } return cache; }
public Map<Class<?>, Boolean> handlerSharableCache() { Map<Class<?>, Boolean> cache = handlerSharableCache; if (cache == null) { // Start with small capacity to keep memory overhead as low as possible. handlerSharableCache = cache = new WeakHashMap<Class<?>, Boolean>(4); } return cache; }
@Override protected Map<Class<?>, String> initialValue() { return new WeakHashMap<Class<?>, String>(); } };
/** * Constructs a CachingProviderManager. */ public CachingProviderRegistry() { this.cachingProviders = new WeakHashMap<ClassLoader, LinkedHashMap<String, CachingProvider>>(); this.classLoader = null; }
@Override protected Map<Stack<?>, WeakOrderQueue> initialValue() { return new WeakHashMap<Stack<?>, WeakOrderQueue>(); } };
@Override public <K1, V1> Map<K1, V1> setMap(Map<K1,V1> map) { map = new WeakHashMap<>(); return map; }
@Override public <K1, V1> Map<K1, V1> setMap(Map<K1,V1> map, int initCapacity) { map = new WeakHashMap<>(initCapacity); return map; }
@Override public Map<K,V> newMap() { return new WeakHashMap<>(); }
@Override public Map<K,V> newMap(int initCapacity) { return new WeakHashMap<>(initCapacity); }
public static <K,V> WeakHashMap<K,V> newWeakHashMap() { return new WeakHashMap<>(); }
public CaffeineCachingProvider() { this.cacheManagers = new WeakHashMap<>(1); }
@Override public Set<K> newSet() { return Collections.newSetFromMap(new WeakHashMap<>()); }
Set<Object> weakHashSet = Collections.newSetFromMap( new WeakHashMap<Object, Boolean>());
@Override public Set<K> newSet(Collection<K> init) { Set<K> set = Collections.newSetFromMap(new WeakHashMap<>()); set.addAll(init); return set; }
/** * <p> * Registers the given object. Used by the reflection methods to avoid * infinite loops. * </p> * * @param value * The object to register. */ static void register(final Object value) { if (value != null) { final Map<Object, Object> m = getRegistry(); if (m == null) { REGISTRY.set(new WeakHashMap<>()); } getRegistry().put(value, null); } }
public void testAwaitDone_FinalizationPredicate() { final WeakHashMap<Object, Object> map = new WeakHashMap<>(); map.put(new Object(), Boolean.TRUE); GcFinalization.awaitDone( new FinalizationPredicate() { public boolean isDone() { return map.isEmpty(); } }); assertTrue(map.isEmpty()); }
data = cache.get(loader); if (data == null) { Map<ClassLoader, ClassLoaderData> newCache = new WeakHashMap<ClassLoader, ClassLoaderData>(cache); data = new ClassLoaderData(loader); newCache.put(loader, data);
@Test @Ignore("Intended for use during development only") public void shouldBeFasterThanSynchronizedMap() throws InterruptedException { Map<Integer, WeakReference<String>> synchronizedMap = Collections.synchronizedMap(new WeakHashMap<Integer, WeakReference<String>>()); StopWatch mapTime = timeMultiThreaded("SynchronizedMap", synchronizedMap, v -> new WeakReference<>(String.valueOf(v))); System.out.println(mapTime.prettyPrint()); this.map.setDisableTestHooks(true); StopWatch cacheTime = timeMultiThreaded("WeakConcurrentCache", this.map, String::valueOf); System.out.println(cacheTime.prettyPrint()); // We should be at least 4 time faster assertThat(cacheTime.getTotalTimeSeconds(), is(lessThan(mapTime.getTotalTimeSeconds() / 4.0))); }