【发布时间】:2015-11-03 17:51:41
【问题描述】:
我想填充超过5亿行的数据库表,我有下面的insert方法:
public void insertRecord(Record rec) throws SQLException, ClassNotFoundException {
if (this.isTableExists(this.TABLE_NAME)) {
Connection conn = this.getConnection();
conn.setAutoCommit(true);
PreparedStatement ps = conn.prepareStatement("insert into "+this.TABLE_NAME+" ("+this.NODE_ID_COL+", "+this.LAT_COL+", "+this.LNG_COL+", "+this.XML_PATH_COL+") values (?, ?, ?, ?)");
ps.setString(1, rec.getNodeID());
ps.setString(2, rec.getLat());
ps.setString(3, rec.getLng());
ps.setString(4, rec.getPath());
ps.addBatch();
ps.executeBatch();
ps.close();
conn.close();
} else {
Log.e(TAG, "insertRecord", "table: ["+this.TABLE_NAME+"] does not exist");
}
}
我的问题是,因为我将插入大量行:
- 我应该在上面发布的方法中使用线程吗?
- 这种情况的最佳做法是什么?
- 在这种情况下 ExecutorService 是否会产生糟糕的性能?
【问题讨论】:
标签: java multithreading sqlite jdbc executorservice