Java: any problems/negative sides of keeping SoftReference to ArrayList in HttpSession?
Posted
by westla7
on Stack Overflow
See other posts from Stack Overflow
or by westla7
Published on 2010-03-16T23:40:36Z
Indexed on
2010/03/16
23:41 UTC
Read the original article
Hit count: 227
My code is doing the following (just as an example, and the reason that I specify package path to java.lang.ref.SoftReference is to note that it's not my own implementaiton :-):
...
List<String> someData = new ArrayList<String>();
someData.add("Value1");
someData.add("Value2");
...
java.lang.ref.SoftReference softRef = new SoftReference(someData);
...
HttpSession session = request.getSession(true);
session.setAttribute("mySoftRefData", softRef);
...
and later:
...
java.lang.ref.SoftReference softRef = session.getAttribute("mySoftRefData");
if (softRef != null && softRef.get() != null) {
List<String> someData = (List<String>)softRef.get();
// do something with it.
}
...
Any disadvantages? Which I do not see? Thank you!
© Stack Overflow or respective owner