字符串连接期间的java.lang.OutOfMemoryError

时间:2015-12-01 05:44:18

标签: java out-of-memory string-concatenation

我在字符串连接期间得到java.lang.OutOfMemoryError。有人可以帮我摆脱这个吗?以下是我的代码的外观。整个blokc是在一个循环下运行的,当它处理" str"的字符串连接时,它会抛出OutofemoryError。对此的任何帮助都非常感激。

while 1:

    answer = input("What is your favorite eldest daughter's name?   ").lower()

    if answer == "a" or answer == "al": #assuming this is the right answer
        print("Of course, we all knew that")
        break
    elif answer == "c" or answer == "chris":
        print("""Oh she must be standing right there.
    But that\'s not it, try again.""")

    elif answer == "e" or answer == "ed":
        print("Not even the right gender. Try again.")
    elif answer == "n" or answer == "nic":
        print("Only biological children please.")

    else:
        print("I'm sorry. Only children. Were you thinking of the dogs?")

例外。

for (long j = mincollectiontime; j <= maxcollectiontime; j = j
        + timeintreval) {
    query = "select count(*) table1";

    ResultSet result2 = VerticaDBHandler.executequery(con2, query);
    System.out.println("Query:- " + query);

    String str = "";
    if (result2.isBeforeFirst()) {
        if (mysqlconn == null) {
            mysqlconn = DatabaseHandler.openDB();
        }

        while (result2.next()) {
            int isgap = Integer.parseInt(result2.getString(1));
            if (isgap == 0) {
                Date startime = EpochTimeHandler.epochToTimeStamp(j);
                Date endtime = EpochTimeHandler.epochToTimeStamp(j
                        + timeintreval);
                str = "NO DATA BETWEEN " + startime + " --- " + endtime
                        + " forInstanceId: " + instanceid
                        + " --InstanceName: " + instanceName + " in "
                        + perfTables[i];
                DatabaseHandler.LoadDB_dataGaps(mysqlconn,
                        perfTables[i], instanceid, instanceName,
                        VirtType, BelongstoDataCenter,
                        startime.toString(), endtime.toString(), str);
                System.out.println(str);
                str = "";
            } else {
                System.out.println("No Gap Seen");
            }
        }
    }
}

2 个答案:

答案 0 :(得分:0)

似乎这就是问题。

for (long j = mincollectiontime; j <= maxcollectiontime; j = j + timeintreval) 

你肯定排除了最大长度并在功能中打电话。请发布更多代码,以便发现具体问题。

答案 1 :(得分:0)

可能是这个问题与字符串分词无关,我认为这个问题与Heap大小有关。一旦增加IDE的堆大小并运行程序。