2021年1月3日星期日

"statistics unavailable at this time" when trying to print String Pool information?

I am following a udemy course on java performance management and I am coming across an issue that is preventing me from printing out information for the String pool. This is what I get when I attempt to add ten million String objects to the pool:

E:\IntelliJ Projects\ExploringStrings\src>java -XX:+PrintStringTableStatistics Main  Elapsed time was 28311 ms.  SymbolTable statistics:  Number of buckets       :     20011 =    160088 bytes, each 8  Number of entries       :     20527 =    492648 bytes, each 24  Number of literals      :     20527 =    776904 bytes, avg  37.848  Total footprint         :           =   1429640 bytes  Average bucket size     :     1.026  Variance of bucket size :     1.033  Std. dev. of bucket size:     1.017  Maximum bucket size     :         9  statistics unavailable at this moment    

This is what I get when I run the program with an empty main method:

E:\IntelliJ Projects\ExploringStrings\src>java -XX:+PrintStringTableStatistics Main  SymbolTable statistics:  Number of buckets       :     20011 =    160088 bytes, each 8  Number of entries       :     16615 =    398760 bytes, each 24  Number of literals      :     16615 =    608976 bytes, avg  36.652  Total footprint         :           =   1167824 bytes  Average bucket size     :     0.830  Variance of bucket size :     0.837  Std. dev. of bucket size:     0.915  Maximum bucket size     :         9  StringTable statistics:  Number of buckets       :     65536 =    524288 bytes, each 8  Number of entries       :      1734 =     27744 bytes, each 16  Number of literals      :      1734 =    112456 bytes, avg  64.854  Total footprsize_t         :           =    664488 bytes  Average bucket size     :     0.026  Variance of bucket size :     0.027  Std. dev. of bucket size:     0.163  Maximum bucket size     :         2  

This is the code that attempts to add 10 million Strings to the pool:

import java.util.ArrayList;  import java.util.Date;  import java.util.List;    public class Main {        public static void main(String[] args) {            Date start = new Date();            List<String> strings = new ArrayList<String>();            for(Integer i = 1; i < 10000000; i++) {              String s =  i.toString().intern(); //Adds new string object to the string pool              strings.add(s);          }            Date end = new Date();          System.out.println("Elapsed time was " + (end.getTime() - start.getTime()) + " ms.");        }  }  

So, my question is: Why can't I print out information for the String pool when I attempt to add 10 million objects, but my instructor can? I am failing to understand the reasoning as this is pretty beyond my level of Java programming. Thank you all.

https://stackoverflow.com/questions/65556454/statistics-unavailable-at-this-time-when-trying-to-print-string-pool-informati January 04, 2021 at 08:46AM

没有评论:

发表评论