关于Java String Pool的一些查询 [英] Some queries regarding Java String Pool

查看:122
本文介绍了关于Java String Pool的一些查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于java字符串池的以下查询:


  1. 它是java堆的一部分吗?它是它的一部分JVM的本机堆?。据我所知是第一个。


  2. 我们对这个字符串池的大小有限制吗?或者是用户可配置?


  3. 在以下两个陈述中

      String str =Stack; 
    String str2 = str.concat(overflow);


根据我的理解,第一个字符串文字将是字符串池的一部分,但之后我在相同的字符串池对象上连接,它将创建新的字符串对象,所以这个对象是在字符串池中分配还是在字符串池外的java堆中? / p>

4。我假设字符串池大小是固定的,那么如果这个字符串池被完全占用会怎么样?gc会清理字符串池吗?或者JVM可以扩展字符串池大小?

解决方案

在当前的Sun / Oracle实现中,interned字符串将与Java数据库一起永久生成。字符串没有单独的内存区域。



此区域的最大大小可通过命令行选项进行配置( -XX:MaxPermGen 或其他东西)。



一般来说 concat 会创建一个新的字符串分配为任何其他对象。



如果PermGen填满,则会得到 OutOfMemoryError 。 GC通常在PermGen上运行,但不太频繁。



所有这些都可能在实现和版本之间发生变化。


I have following queries regarding java string pool:

  1. Is it a part of java heap of is it a part of native heap of JVM?.As per my understanding its the first one.

  2. Do we have any limit on the size of this string pool?Or is it user configurable ?

  3. In the following two statement

    String str = "Stack";
    String str2 = str.concat("overflow");
    

As per my understanding first string literal will be part of the string pool,but after that i did concat on the same string pool object,and it will create new string object,so will this object be allocated in the string pool or it will be in the java heap outside string pool?

4 . I am assuming that the string pool size is fixed,then what happens if this string pool get fully occupied?Do gc will clean up string pool?or JVM can expand the string pool size?

解决方案

In the current Sun/Oracle implementation interned strings will be in the permanent generation of the Java heap, along with class data. There is no separate memory area for strings.

The maximum size of this area is configurable with a command line option (-XX:MaxPermGen or something).

Generally concat will create a new String object allocated as any other.

If the PermGen fills up, then you get an OutOfMemoryError. GC typically runs on the PermGen, but less frequently.

All this is subject to change between implementations and versions.

这篇关于关于Java String Pool的一些查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆