Example #1
0
  public void updateCrawlerTaskList(List<CrawlerTask> list) throws Throwable {
    conn.setAutoCommit(false);
    PreparedStatement statement =
        conn.prepareStatement(
            "UPDATE `yamaloo`.`crawlertask`"
                + " SET `Status` = ?,"
                + " `CrawlBeginTime` = ?,"
                + " `CrawlEndTime` = ?,"
                + " `RetryCount` = ?,"
                + " `ContentType` = ?"
                + " WHERE CrawlerTaskID = ?");

    int count = 0;
    for (CrawlerTask task : list) {
      statement.setString(1, task.getStatus().toString());
      statement.setTimestamp(2, task.getCrawlBeginTime());
      statement.setTimestamp(3, task.getCrawlEndTime());
      statement.setInt(4, task.getRetryCount());
      statement.setString(5, task.getContentType());
      statement.setInt(6, task.getCrawlerTaskID());

      statement.addBatch();
      count++;

      if (count >= 1000) {
        count = 0;
        statement.executeBatch();
        conn.commit();
      }
    }

    statement.executeBatch();
    conn.commit();

    statement.close();
    conn.setAutoCommit(true);
  }