国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Is it a problem on Regex or Static

2019-11-18 11:33:40
字體:
來源:轉載
供稿:網友

I have met a PRoblem, which will seriously cause JVM problem.

I try to build a class to solve String Operation with Regular EXPression (java.util.regex.*)

I define all the method as a static one, thus i can use the class to parse String without a instance. But when i use the method many times, just found the memory is quickly exhausted. ( i use java -verbose:gc to observe the status). finally , i focus on the return type of the method, i directly return the String with "m.group(1)" (m is a instance of java.util.regex.Matcher). Is it a problem of regex or static or both? i didn't know the answer.

The original code are:

    public static String getFirstGroup(String regex, String original) {
            Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
            Matcher m = p.matcher(original);
            if (m.find()) {
                    String result = m.group(1);
                   m = null;
                   return result;
            } else {
                      return "";
             }
    }
The strange thing is when i use is to parse one same String for many times, on problem occurs.

Then i make some change:

    public static String getFirstGroup(String regex, String original) {
            Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
            Matcher m = p.matcher(original);
            if (m.find()) {
                    String result = new String(m.group(1));
                   m = null;
                   return result;
            } else {
                      return "";
             }
    }
The problem disappeared. So i confused with the problem.



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 罗城| 体育| 三台县| 福贡县| 嘉荫县| 丹巴县| 罗田县| 富裕县| 宜良县| 万安县| 桐柏县| 兴和县| 杭州市| 仙桃市| 北流市| 巍山| 新巴尔虎右旗| 伽师县| 清镇市| 阿坝县| 会同县| 舞钢市| 象山县| 石渠县| 通州区| 通许县| 德昌县| 清苑县| 莎车县| 额敏县| 原平市| 扬中市| 什邡市| 容城县| 孟连| 英德市| 天长市| 通辽市| 新建县| 定安县| 昌黎县|