Path: csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: how actually string store in java machine Date: Tue, 25 Mar 2014 14:00:34 -0700 Organization: A noiseless patient Spider Lines: 44 Message-ID: References: <8f7d9272-4b25-44c9-8c31-93ea754be4cb@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 25 Mar 2014 21:00:38 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="5aa64ebf9a53573f97c75abba936b0e2"; logging-data="23940"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+iB/VeLKpYCX6iKxX2ckT/uJgnUOg2ovY=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: Cancel-Lock: sha1:/8w0jQ4RUjBwoQpBJz1r/azwoD4= Xref: csiph.com comp.lang.java.programmer:27865 On 3/25/2014 1:19 PM, Jeff Higgins wrote: > On 03/25/2014 04:16 PM, Jeff Higgins wrote: >> > Oops. > > > Quoted from your link: "Summary "Despite serious optimizations done in the String.intern() implementation in Java 7+, it still takes a noticeable time to run (noticeable for CPU sensitive applications). The simple example in this article runs 3.5 times faster without calls to String.intern(). You should not use String.intern() as a safety net, passing every long living string into it. Instead process only fields with a limited number of possible distinct values (for example, states/provinces if processing addresses) - memory savings in this situation will definitely pay off the initial CPU costs of String.intern()." * * * Basically the "you should not use String.intern() ... passing every ... string into it." Is the money shot. If you have a string that's obviously repetitious (like a field for states or countries) it might be useful, other wise not so much. Also, using String.intern() heavily requires that you increase memory available to it. "The requirement to set -XX:StringTableSize=N JVM parameter in advance and dealing with its fixed value" That alone would make me want to use a HashSet instead.