To add content to the runtime pool, use the string. Intern () Native method. The function of this method is: if the pool already contains a string equal to this string object, a string object representing this string in the pool is returned; otherwise, add the string contained in this string object to the constant pool and return a reference to this string object. Since the constant pool is allocated in the method area, we can use-XX: permsize and-XX: maxpermsize to limit the size of the Method Area and indirectly limit the capacity of the output pool. The Code is as follows:
Package OOM; import Java. util. arraylist; import Java. util. list;/*** run time pool overflow * @ author Madison * @ date 2014-7-11 * VM ARGs:-XX: permsize = 10 m-XX: maxpermsize = 10 m */public class runtimeconstantpooloom {public static void main (string [] ARGs) {// use list to keep constant pool reference, avoid full GC collection of constant pool behavior list <string> List = new arraylist <string> (); int I = 0; while (true) list. add (string. valueof (I ++ ). intern ());}}
Running result:
Exception in thread "Main" Java. Lang. outofmemoryerror: permgen Space
At java. Lang. String. Intern (native method)
At oom. runtimeconstantpooloom. Main (runtimeconstantpooloom. Java: 20)
From the running results, we can see that the runtime frequent volume pool overflows. After the outofmemoryerror is followed by the prompt message "permgen space", indicating that the runtime frequent volume pool belongs to the method zone (permanent generation in the hotspot virtual machine).
I want to know what to do later and listen to the next Decomposition
This article is from the "2377209" blog. For more information, contact the author!