René's URL Explorer Experiment


Title: Java String Pool—How Unbounded intern() Causes PermGen OOM

Open Graph Title: Java String Pool—How Unbounded intern() Causes PermGen OOM

Description: After 3 days, a trading platform hit PermGen OOM from unbounded String.intern() on 500K XML tags. Learn the one JVM flag that can prevent it.

Open Graph Description: After 3 days, a trading platform hit PermGen OOM from unbounded String.intern() on 500K XML tags. Learn the one JVM flag that can prevent it.

Opengraph URL: https://thecodeforge.io/java/string-pool-java/

direct link

Domain: thecodeforge.io


Hey, it has json ld scripts:
{
  "@context": "https://schema.org",
  "@type": "TechArticle",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://thecodeforge.io/java/string-pool-java/"
  },
  "headline": "Java String Pool—How Unbounded intern() Causes PermGen OOM",
  "description": "After 3 days, a trading platform hit PermGen OOM from unbounded String.intern() on 500K XML tags. Learn the one JVM flag that can prevent it.",
  "keywords": "Java String Pool—How Unbounded intern() Causes PermGen OOM, Java, Advanced, Strings, After 3 days, a trading platform hit PermGen OOM from unbounded String.intern() on 500K XML tags. Learn the one JVM flag that can prevent it.",
  "proficiencyLevel": "Expert",
  "author": {
    "@type": "Person",
    "@id": "https://thecodeforge.io/about/#naren",
    "name": "Naren",
    "url": "https://thecodeforge.io/about/"
  },
  "publisher": {
    "@type": "Organization",
    "@id": "https://thecodeforge.io/#org",
    "name": "TheCodeForge",
    "url": "https://thecodeforge.io",
    "logo": {"@type": "ImageObject", "url": "https://thecodeforge.io/assets/og-image.png"}
  },
  "datePublished": "2026-03-05T00:00:00+00:00",
  "dateModified": "2026-08-30T00:00:00+00:00",
  "url": "https://thecodeforge.io/java/string-pool-java/",
  "inLanguage": "en",
  "educationalLevel": "Advanced",
  "image": "https://thecodeforge.io/assets/og-image.png",
  "isPartOf": {"@id": "https://thecodeforge.io/#website"}
}
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    {"@type": "ListItem", "position": 1, "name": "Home", "item": "https://thecodeforge.io/"},
    {"@type": "ListItem", "position": 2, "name": "Java", "item": "https://thecodeforge.io/java/"},
    {"@type": "ListItem", "position": 3, "name": "Java String Pool—How Unbounded intern() Causes PermGen OOM", "item": "https://thecodeforge.io/java/string-pool-java/"}
  ]
}
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "Is the Java String Pool thread-safe?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Yes, but with nuance. The pool's underlying hash table uses striped locking — each bucket has its own lock rather than one global lock. This means concurrent intern() calls on strings hashing to different buckets can proceed in parallel. However, high throughput on a narrow set of hash buckets can still cause contention. The pool structure itself is safe; the performance characteristics under concurrency require profiling."
      }
    },
    {
      "@type": "Question",
      "name": "Does String.valueOf() or Integer.toString() put the result in the pool?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "No. Methods like String.valueOf(42) and Integer.toString(someNumber) return new heap-allocated String objects, not pooled ones. The only way a runtime-created string ends up in the pool is via explicit intern() or if the JVM's G1 deduplication shares its backing byte array (which doesn't affect == equality anyway). If you need the result pooled, call .intern() on the return value — but only if you have a genuine use case for it."
      }
    },
    {
      "@type": "Question",
      "name": "Why does == work for string comparison in some situations but not others?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "The == operator always compares object references — memory addresses. It happens to return true for string literals and compile-time constant concatenations because those all resolve to the same pooled object. It fails for runtime-created strings (new String(), StringBuilder.toString(), method return values) because those are separate heap objects. The safe rule: always use equals() for string value comparison. Treat any == returning true for strings as an implementation detail, not a contract."
      }
    },
    {
      "@type": "Question",
      "name": "How can I check the current size of the String Pool in a running JVM?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Use the 'jcmd' command: 'jcmd  VM.stringtable'. This prints the number of entries, bucket distribution, and memory usage. Alternatively, you can use '-XX:+PrintStringTableStatistics' at JVM startup to see pool details at exit. For live monitoring, JMX MBeans don't expose the pool directly, but 'jcmd' is the standard tool."
      }
    },
    {
      "@type": "Question",
      "name": "What happens if I intern() a very long string (e.g., 1 MB)?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "The entire string gets added to the pool's hash table. On modern JDKs, this is allowed, but it consumes heap space proportional to the string size. Since the pool never shrinks until a full GC, a very long interned string will stay in heap until no references remain. For large strings, consider using a different caching strategy (e.g., a separate WeakHashMap) rather than interning, because intern() is designed for many small strings, not large blobs."
      }
    }
  ]
}

og:typewebsite
og:imagehttps://thecodeforge.io/assets/og-image.png
og:image:width1200
og:image:height630

Links:

TheCodeForge https://thecodeforge.io/
Javahttps://thecodeforge.io/java/
Buy me a coffee https://ko-fi.com/thecodeforge
1Strings in Javahttps://thecodeforge.io/java/strings-java/
2String Methods in Javahttps://thecodeforge.io/java/string-methods-java/
3StringBuilder and StringBuffer in Javahttps://thecodeforge.io/java/stringbuilder-stringbuffer-java/
4String Formatting in Javahttps://thecodeforge.io/java/string-formatting-java/
5Regular Expressions in Javahttps://thecodeforge.io/java/regex-java/
6String Comparison in Javahttps://thecodeforge.io/java/string-comparison-java/
7String Immutability in Javahttps://thecodeforge.io/java/string-immutability-java/
8String Pool in Javahttps://thecodeforge.io/java/string-pool-java/
9String Tokenizer in Javahttps://thecodeforge.io/java/string-tokenizer-java/
10Character Class in Javahttps://thecodeforge.io/java/character-class-java/
11Char Array to String in Java: Four Conversion Methodshttps://thecodeforge.io/java/java-char-array-to-string/
12List to Comma Separated String in Javahttps://thecodeforge.io/java/java-list-to-comma-string/
13Java String contains(): Check for Substringshttps://thecodeforge.io/java/java-string-contains/
14Java Split String: By Delimiter, Regex and Limithttps://thecodeforge.io/java/java-split-string/
15Java String replace(), replaceAll() and replaceFirst()https://thecodeforge.io/java/java-string-replace/
← Back to Java track https://thecodeforge.io/java/
Homehttps://thecodeforge.io/
Javahttps://thecodeforge.io/java/
Follow https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
 ● Production Incidenthttps://thecodeforge.io/java/string-pool-java/#v2-production-incident
 🔎 Debug Guidehttps://thecodeforge.io/java/string-pool-java/#v2-debug-guide
 ⚙ Triage Commandshttps://thecodeforge.io/java/string-pool-java/#v2-triage-commands
Stringshttps://thecodeforge.io/java/strings-java/
Java 8https://thecodeforge.io/interview/java8-interview-questions/
linked listhttps://thecodeforge.io/interview/top-linked-list-interview-problems/
arrayshttps://thecodeforge.io/java/arrays-java/
Spring Boothttps://thecodeforge.io/java/spring-boot-docker/
abstractionhttps://thecodeforge.io/java/abstraction-java/
arrayhttps://thecodeforge.io/dsa/array-data-structure/
→Java String Immutability Stops TOCTOU ExploitsHeavy-load security flaws from mutable StringBuilder? Immutability prevents TOCTOU. Java String's final class and pool ehttps://thecodeforge.io/java/string-immutability-java/
→Java Strings — Why == Broke Authentication in ProductionUsing == on Java strings caused a silent production failure. This article explains the root cause and how to debug strinhttps://thecodeforge.io/java/strings-java/
→Java ThreadLocal Leak — Missing remove() Cost 2.8GB HeapPayment service OOM at Black Friday: heap grew 180MB/hr, 1.1GB→2.8GB old gen. 4 threads @ 800MB—missing remove(). Fix wihttps://thecodeforge.io/java/java-memory-leaks-prevention/
→JVM Memory Model — OOMKilled by Non-Heap OverheadJVM's -Xmx4g in 4GB container leaves zero headroom; non-heap overhead ~490 MB triggers OOMKilled. Avoid silent crashes whttps://thecodeforge.io/java/jvm-memory-model/
→Java Classes & Objects — Heap Leaks from Static ReferencesStatic HashMaps caused OOM after 72 hours by pinning millions of objects. Learn the lifecycle patterns that prevent memohttps://thecodeforge.io/java/classes-objects-java/
Numerical Integration — Simpson's Rule and TrapezoidalIntermediatehttps://thecodeforge.io/dsa/numerical-integration-methods/
Follow https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
←PreviousString Immutability in Javahttps://thecodeforge.io/java/string-immutability-java/
NextString Tokenizer in Java→https://thecodeforge.io/java/string-tokenizer-java/
LinkedIn https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
Facebook https://www.facebook.com/profile.php?id=61583020033815
YouTube https://www.youtube.com/channel/UCMar7CF2EmCF1I2tw1tNVuQ
Javahttps://thecodeforge.io/java/
Pythonhttps://thecodeforge.io/python/
C / C++https://thecodeforge.io/c-cpp/
JavaScripthttps://thecodeforge.io/javascript/
DSAhttps://thecodeforge.io/dsa/
Databasehttps://thecodeforge.io/database/
System Designhttps://thecodeforge.io/system-design/
DevOpshttps://thecodeforge.io/devops/
C# / .NEThttps://thecodeforge.io/csharp/
PHPhttps://thecodeforge.io/php/
ML / AIhttps://thecodeforge.io/ml-ai/
Interviewhttps://thecodeforge.io/interview/
CS Fundamentalshttps://thecodeforge.io/cs-fundamentals/
Rusthttps://thecodeforge.io/rust/
Toolshttps://thecodeforge.io/tools/
Cheatsheetshttps://thecodeforge.io/cheatsheets/
Mobilehttps://thecodeforge.io/mobile/
Data Analyticshttps://thecodeforge.io/data-analytics/
Securityhttps://thecodeforge.io/security/
Frontendhttps://thecodeforge.io/frontend/
Data Engineeringhttps://thecodeforge.io/data-engineering/
Testinghttps://thecodeforge.io/testing/
Cloudhttps://thecodeforge.io/cloud/
Observabilityhttps://thecodeforge.io/observability/
Web Platformhttps://thecodeforge.io/web-platform/
🧯 Errors Explainedhttps://thecodeforge.io/errors/
⚒ Blueprintshttps://thecodeforge.io/blueprints/
⌨ Practicehttps://thecodeforge.io/practice/
Interview Prephttps://thecodeforge.io/interview/
DSA Problemshttps://thecodeforge.io/dsa/
Developer Toolshttps://thecodeforge.io/tools/
Cheat Sheetshttps://thecodeforge.io/cheatsheets/
Abouthttps://thecodeforge.io/about/
Sitemaphttps://thecodeforge.io/sitemap.xml
Privacyhttps://thecodeforge.io/privacy.html

Viewport: width=device-width, initial-scale=1.0

Robots: max-image-preview:large


URLs of crawlers that visited me.