weakhashmap Questions
7
Solved
Can the following piece of code be rewritten w/o using Collections.synchronizedMap() yet maintaining correctness at concurrency?
Collections.synchronizedMap(new WeakHashMap<Class, Object>()...
Spiritism asked 13/2, 2010 at 0:16
6
Solved
In the following code example when keys are set to null and System.gc() is called, the WeakHashMap loses all mappings and is emptied.
class WeakHashMapExample {
public static void main(String[] a...
Pruitt asked 23/9, 2013 at 17:14
5
Solved
If I iterate over the key set of a WeakHashMap, do I need to check for null values?
WeakHashMap<MyObject, WeakReference<MyObject>> hm
= new WeakHashMap<MyObject, WeakReference<M...
Proudlove asked 28/5, 2011 at 0:45
2
Solved
I am trying to use WeakHashMap as a concurrent Set of weak references.
this.subscribers =
Collections.synchronizedSet(
Collections.newSetFromMap(
new WeakHashMap <>()
)
);
When an e...
Paget asked 13/10, 2018 at 5:30
2
Solved
In Java there is a data structure called a WeakHashMap that stores weak references as keys. Whenever the weak references are taken out of memory the entry is removed from the map.
If I have a dat...
Burlesque asked 10/8, 2012 at 21:49
4
In the code below nameRef.get() is null , after name = null and System.gc().
import java.lang.ref.WeakReference;
public class Main {
public static void main(String[] args) {
String name = new ...
Broderick asked 2/3, 2019 at 13:42
3
I invesigate WeakHashMap ource code to have more knowledge about WeakReference
I have found that entry looks like this:
private static class Entry<K,V> extends WeakReference<Object> i...
Weller asked 29/1, 2017 at 9:28
1
Solved
First of all I would like to clarify my understanding of the WeakReference as the following question depends on the same.
static void test() {
Person p = new Person();
WeakReference<Person&g...
Occasionally asked 4/6, 2018 at 18:45
6
Solved
I create a WeakHashMap as
WeakHashMap<Employee,String> map = new WeakHashMap<Employee,String>();
map.put(emp,"hello");
where emp is an Employee object. Now if I do emp = null or say ...
Borak asked 15/5, 2012 at 11:25
5
Solved
WeakHashMap is an implementation of Map interface where the memory of the value object can be reclaimed by Grabage Collector
if the corresponding key is no longer referred by any section of ...
Terceira asked 23/12, 2013 at 11:50
2
Solved
I have to solve the following scenario, in a Spring Security 3.2.5-RELEASE with Spring Core 4.1.2-RELEASE application running Java 1.7 on wildfly 8.1.
user 'bob' logs in
and Admin deletes 'bob'...
Multiracial asked 8/2, 2016 at 18:21
3
Solved
Key object in WeakHashMap became weakly reachable. And map should be remove the entry after GC. But a strong reference to the value object remains. Why?
The same behavior is observed with guava we...
Skyeskyhigh asked 19/1, 2016 at 13:32
8
Solved
What is a WeakHashMap and when should one be using it? What are the differences between a WeakHashMap and a HashMap?
Oglesby asked 1/4, 2011 at 9:7
1
Solved
I am managing a project in Java that stores user data. Users can be online, or offline. When users are online, their data is loaded into the data object for easy accessibility, and offloaded when t...
Vesicant asked 13/4, 2014 at 3:53
1
Solved
Is HashSet<WeakReference<T>> the Set equivalent of WeakHashMap<T>? That is, will entries be automatically deleted when they are no longer referenced?
If not, what is the equivale...
Tenderhearted asked 14/10, 2013 at 19:2
2
Solved
My application logs the usage of certain objects - my setup uses AspectJ to identify the contexts I'm interested in and logs these usages. I later load the log files for analysis, but for efficienc...
Immingle asked 5/6, 2013 at 14:43
4
Solved
I recently found out about the WeakHashMap data structure in Java.
However, I don't understand what it means by it garbage-collects a mapping when it is no longer in ordinary use. How does the dat...
Clausewitz asked 23/6, 2012 at 23:27
1
Solved
Javadocs says "When a key has been discarded its entry is effectively removed from the map".
But unless there is another thread that occasionally removes such Map.Entry entries, won't the value ob...
Vitriform asked 6/2, 2012 at 20:14
2
Solved
I need to associate some data with a key for its lifetime, so I am using a WeakHashMap. However, in addition I need to get a key by its corresponding value. The easy way to do it is to hold on to t...
Elle asked 8/11, 2011 at 14:28
4
Solved
So the Java WeakHashMap lets one create a map whose entries are removed if its keys become weak. But how can I create a Map whose entries are removed when the values in the map become weak? The rea...
Basion asked 14/4, 2011 at 16:30
1
Solved
We have a Scala server that is getting a node tree using Protocol Buffers over a socket and we need to attach additional data to each node.
In a single threaded context and when both the node tree...
Darrondarrow asked 17/11, 2010 at 5:3
4
Solved
I have read many people really like the MapMaker of Google Guava (Collections), however I cannot see any good uses of it.
I have read the javadoc, and it says that it behaves like ConcurrentHashMa...
Plow asked 1/9, 2010 at 11:52
2
Solved
In the Javadoc of WeakHashMap.html, it said
"Each key object in a WeakHashMap is
stored indirectly as the referent of a
weak reference. Therefore a key will
automatically be removed only aft...
Diarthrosis asked 18/3, 2010 at 21:19
1
© 2022 - 2024 — McMap. All rights reserved.