???Java???????????????
???????????? ???????[ 2015/5/7 11:18:54 ] ???????????????
?????????????????????????
????0;manual time=0.001 sec
????50000;manual time=0.03 sec
????100000;manual time=0.034 sec
????150000;manual time=0.008 sec
????200000;manual time=0.019 sec
????250000;manual time=0.011 sec
????300000;manual time=0.011 sec
????350000;manual time=0.008 sec
????400000;manual time=0.027 sec
????450000;manual time=0.008 sec
????500000;manual time=0.009 sec
????550000;manual time=0.008 sec
????600000;manual time=0.008 sec
????650000;manual time=0.008 sec
????700000;manual time=0.008 sec
????750000;manual time=0.011 sec
????800000;manual time=0.007 sec
????850000;manual time=0.008 sec
????900000;manual time=0.008 sec
????950000;manual time=0.008 sec
????1000000;manual time=0.008 sec
??????JVM???????????????д????????????????????????????????????????String.valueOf(0<N<1??000??000??000)???????????????????????-Xmx1280M???????????????????2.5M?????????????JVM???????(size=1??000??003??????????潲??JVM???????????????????????????JVM??????????12.72M????????????????????棨5??????????????????????????????????????????????????
??????Java 7u40+???Java 8?е?String.intern()
????Java7u40?汾??????????????С?????????????????£???60013.??????????????а??????30000???????????????????????????????????????????????????????????-XX:+PrintFlagsFinal JVM?????????????
???????????????????Java 8???????????????Java 8??????-XX:StringTableSize??????????Java 7??????????????????Java 8????????С?????60013??
????50000;time=0.019 sec
????100000;time=0.009 sec
????150000;time=0.009 sec
????200000;time=0.009 sec
????250000;time=0.009 sec
????300000;time=0.009 sec
????350000;time=0.011 sec
????400000;time=0.012 sec
????450000;time=0.01 sec
????500000;time=0.013 sec
????550000;time=0.013 sec
????600000;time=0.014 sec
????650000;time=0.018 sec
????700000;time=0.015 sec
????750000;time=0.029 sec
????800000;time=0.018 sec
????850000;time=0.02 sec
????900000;time=0.017 sec
????950000;time=0.018 sec
????1000000;time=0.021 sec
???????????
??????????μ????????????????????????????????????????????????????????10000??????????????????????-verbose:gc JVM???????????????????????????????????????????η??????????????-Xmx????????ж??????
???????????????????testStringPoolGarbageCollection?????JVM???????????????—????????????????????Java 6?????PermGen??С???????????????????????????????????????2???????????????Java 7.
????????????????????б?????????????????Java 6??????????????????????????磺-Xmx128M???-Xmx1280M??10?????????????????????????????????????????????????????棬??Java 7??????????????????????????
????/**
????-Testing String.intern.
????*
????-Run this class at least with-verbose:gc JVM parameter.
????*/
????public class InternTest{
????public static void main(String[]args){
????testStringPoolGarbageCollection();
????testLongLoop();
????}
????/**
????-Use this method to see where interned strings are stored
????-and how many of them can you fit for the given heap size.
????*/
????private static void testLongLoop()
????{
????test(1000*1000*1000);
????//uncomment the following line to see the hand-written cache performance
????//testManual(1000*1000*1000);
????}
????/**
????-Use this method to check that not used interned strings are garbage collected.
????*/
????private static void testStringPoolGarbageCollection()
????{
????//first method call-use it as a reference
????test(1000*1000);
????//we are going to clean the cache here.
????System.gc();
????//check the memory consumption and how long does it take to intern strings
????//in the second method call.
????test(1000*1000);
????}
????private static void test(final int cnt)
????{
????final List<String>lst=new ArrayList<String>(100);
????long start=System.currentTimeMillis();
????for(int i=0;i<cnt;++i)
????{
????final String str="Very long test string??which tells you about something"+
????"very-very important??definitely deserving to be interned#"+i;
????//uncomment the following line to test dependency from string length
????//final String str=Integer.toString(i);
????lst.add(str.intern());
????if(i%10000==0)
????{
????System.out.println(i+";time="+(System.currentTimeMillis()-start)/1000.0+"sec");
????start=System.currentTimeMillis();
????}
????}
????System.out.println("Total length="+lst.size());
????}
????private static final WeakHashMap<String??WeakReference<String>>s_manualCache=
????new WeakHashMap<String??WeakReference<String>>(100000);
????private static String manualIntern(final String str)
????{
????final WeakReference<String>cached=s_manualCache.get(str);
????if(cached!=null)
????{
????final String value=cached.get();
????if(value!=null)
????return value;
????}
????s_manualCache.put(str??new WeakReference<String>(str));
????return str;
????}
????private static void testManual(final int cnt)
????{
????final List<String>lst=new ArrayList<String>(100);
????long start=System.currentTimeMillis();
????for(int i=0;i<cnt;++i)
????{
????final String str="Very long test string??which tells you about something"+
????"very-very important??definitely deserving to be interned#"+i;
????lst.add(manualIntern(str));
????if(i%10000==0)
????{
????System.out.println(i+";manual time="+(System.currentTimeMillis()-start)/1000.0+"sec");
????start=System.currentTimeMillis();
????}
????}
????System.out.println("Total length="+lst.size());
????}
????}
???????
????????Java 6????ù????????С??PermGen??????????String.intern()????
????Java7??8??????????????????????????????????????????????ó????????????
??????Java 7??8?????-XX:StringTableSize?????????????Map???С???????????????????HashMap?????????????????????????????????????????????????ó???С????????????????2????????????????????????String.intern????????????????????????????β?????????С?????(????????????java WeakHashMap??????4-5???????)??
??????Java 6??7??Java7u40???????-XX:StringTableSize?????????1009??Java7u40????????????60013??Java 8?????????????
???????????????????????????ο???-XX:+PrintStringTableStatistics JVM?????????????ù?????????????????????????????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????