For a long time, map is very popular. In small-scale applications, map is nothing to use. However, a large number of applications require attention in terms of Memory Applications.
A few months ago, map was used when I was working on the project. In an article, I remember that there was a problem with map recycling. After a try, when it was set to null, still cannot be effectively recycled. I found some information and finally weakhashmap. When no Pointer Points to value, the key will be recycled and a cachemap will be used. I need to add another method.
Package org. OFBiz. Payment. Common;
Import java. util. iterator;
Import java. util. weakhashmap;
/**
* @ Author zxub 2006-3-22 10:03:22
*/
Public class cachemap extends weakhashmap
{
Public object getkeybyvalue (object value)
{
Object returnvalue = NULL;
Object key = NULL;
For (iterator iter = This. keyset (). iterator (); ITER. hasnext ();)
{
Key = ITER. Next ();
If (this. Get (key). Equals (value ))
{
Returnvalue = key;
Break;
}
}
Return returnvalue;
}
}
The application here is the opposite of map. After testing, the memory can be effectively released.