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 in the project. Article , When no pointer points to the value, the key will be recycled and it will be used for a cachemap. You need to add a method.
Package Org. OFBiz. Payment. Common;
ImportJava. util. iterator;
ImportJava. 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.