首页 > 解决方案 > Java,JDBC被多线程搞砸了?

问题描述

我正在使用 Java、Eclipse IDE 中的 JDBC 从数据库中获取约 20'000 行。

我逐步检查结果集(按 id 排序)。每行都包含有关其先前和后续“标识符”(行的唯一字符串)的信息。因此,对于每一行,我都会检查链条是否损坏,无论出于何种原因。

我下面的方法有效,不要引用我的话,但它似乎对前 10'000 人比对以下人更好。19'999 个条目的错误配额为 335。我亲眼检查了报告的错误是否符合实际,但肯定不是,至少有1个错误。

我错过了什么重要的事情吗?为什么会这样?它几乎看起来像是并行化、多线程等的结果?

int i = 0;
String actualprevious = "", previous = "", next = "";
boolean first = true; // we can't check if the first is in line because it is the first
int errors = 0;

while (rs.next())
{
    if (i%10000==0) { System.out.println("Checked "+(i/10000)+" myriads."); } // inform
    String current = rs.getString("identifier");
                
    if (!current.equals(next)) { System.out.println("Current is: "+current); System.out.println("Expected "+next+" to be next, but "+current+" is."); errors++; } // inform
    // ignore: Document doc = Jsoup.parse(rs.getString("source"));
    next = rs.getString("next");
    if (next==null) { System.out.println("There is no next listed in row "+current+"."); errors++; } // inform
    
    previous = rs.getString("previous");
    if (!first && !actualprevious.equals(previous)) { System.out.println("Expected "+actualprevious+" to be listed as previous, but "+previous+" was in document "+current+"."); errors++; } // inform
    
    actualprevious = current;
    i++; 
    first = false;
}

标签: javajdbc

解决方案


推荐阅读